Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

asp.net - No mapping exists from object type System.String[] to a known managed provider native type

I am getting this error No mapping exists from object type System.String[] to a known managed provider native type. The code is

 Dim conn1 As SqlConnection
        conn1 = New SqlConnection("Data Source=win2008-2;Initial Catalog=h1tm11;User ID=sa;Password=#1cub3123*;Persist Security Info=True;")
        ' Dim conn1 As String = ConfigurationManager _ .ConnectionStrings("Connectionstring").ConnectionString()
        'conn1.ConnectionString = ConfigurationManager.ConnectionStrings("Data Source=win2008-2;Initial Catalog=h1tm11;User ID=sa;Password=#1cub3123*;Persist Security Info=True;").ConnectionString
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.CommandText = "SELECT lat,lng FROM tbl_pincode WHERE codes LIKE @Value"

        Dim addressstring1 As String = txtpostcode.Value.Trim()
        Dim addressstring() As String = Split("addressstring1", ",", 1)

        'SqlCommand cmd = new SqlCommand(query,conn1);
        cmd.Parameters.AddWithValue("@Value", addressstring)
        Dim table As DataTable
        table = New DataTable()
        Dim adapter As SqlDataAdapter = New SqlDataAdapter(cmd)
        adapter.SelectCommand = cmd
        adapter.SelectCommand.Connection = conn1
        adapter.Fill(table)
        '  Dim row As DataRow
        ' For Each number As Integer In New Long()
        For Each row As DataRow In table.Rows

            Dim lat As String = row("lat").ToString()
            Dim lng As String = row("lng").ToString()
            Dim connstring As SqlConnection = New SqlConnection()
            connstring.ConnectionString = ConfigurationManager.ConnectionStrings("Data Source=win2008-2;Initial Catalog=h1tm11;User ID=sa;Password=#1cub3123*;Persist Security Info=True;").ConnectionString
            Dim conn As SqlCommand = New SqlCommand()
            conn.CommandText = "SELECT  *, 6371.01 * ACOS( SIN( CAST((@lat) AS float)*PI()/180 ) * SIN( CAST((store_lat) AS float)*PI()/180 ) + COS( CAST((@lat) AS float)*PI()/180 ) * COS( CAST((store_lat) AS float)*PI()/180 ) * COS( (CAST((store_long) AS float)*PI()/180) - (CAST((@lng) AS float)*PI()/180) ) ) AS distance from storelocator where 6371.01 * ACOS( SIN(CAST((@lat) AS float)*PI()/180 ) * SIN( CAST((store_lat) AS float)*PI()/180 ) + COS(CAST((@lat) AS float)*PI()/180 ) * COS( CAST((store_lat) AS float)*PI()/180 ) * COS( (CAST((store_long) AS float)*PI()/180) - (CAST((@lng) AS float)*PI()/180) ) ) < '" + withddl.SelectedItem.Value + "' order by distance asc;"
            conn.Connection.Open()
            'SqlCommand comm = new SqlCommand(SQL1, conn);
            conn.Parameters.AddWithValue("@lat", lat)
            conn.Parameters.AddWithValue("@lng", lng)

            Dim reader As SqlDataReader = conn.ExecuteReader()

            While (reader.Read())
                Dim area As String = reader("store_name").ToString()
                Dim codes As String = reader("store_address1").ToString()
                litAddress.Text += area + "<br>"
                litAddress.Text += codes + "<br>" + "<br>"
            End While



        Next

the error occurs at adapter.Fill(table) I think the problem is in

Dim addressstring1 As String = txtpostcode.Value.Trim()
    Dim addressstring() As String = Split("addressstring1", ",", 1)

Can someone plz help me out?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

addressstring is a string array.
You can't pass an array as a SQL parameter, since SQL Server does not support arrays.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...