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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…