从对象类型System.String []到已知的托管提供程序本机类型不存在映射

时间:2012-01-27 06:41:30

标签: asp.net vb.net

我收到此错误 从对象类型System.String []到已知的托管提供程序本机类型不存在映射。 代码是

 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

错误发生在adapter.Fill(表) 我认为问题在于

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

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:3)

addressstring是一个字符串数组 您不能将数组作为SQL参数传递,因为SQL Server不支持数组。