没有映射从System.String []对象类型存在一个已知的托管提供原生型 [英] No mapping exists from object type System.String[] to a known managed provider native type
本文介绍了没有映射从System.String []对象类型存在一个已知的托管提供原生型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到这个错误
没有映射从System.String对象类型[]为已知的托管提供原生类型的存在。
在code是
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
在adapter.Fill错误发生(表)
我认为这个问题是在
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)
有人可以plz帮助我吗?
Can someone plz help me out?
推荐答案
addressstring
是一个字符串数组。结果
你不能传递一个数组作为SQL参数,因为SQL Server不支持数组。
addressstring
is a string array.
You can't pass an array as a SQL parameter, since SQL Server does not support arrays.
这篇关于没有映射从System.String []对象类型存在一个已知的托管提供原生型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文