J
JJ297
I have a dropdown list populated via a database. I edited the
dropdown list to have "select a topic" to always appear when the drop
down loads. Now if a user selects a dropdown item it goes into the
datagrid fine, but if a user selects "select a topic" I get an error
message...
Error converting nvarchar to int on adapter.Fill(ds)
Here's the code behind can someone please assist? Thanks!
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
DropDownList2.SelectedIndexChanged
Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("TrainUserConnectionString").ConnectionString)
Dim cmd As New Data.SqlClient.SqlCommand
With cmd
.CommandType = Data.CommandType.StoredProcedure
.CommandText = "Getclassifications1"
If DropDownList2.SelectedValue = "select a topic" Then
Response.Write("Please select a topic")
Else
.Parameters.AddWithValue("classificationid",
DropDownList2.SelectedValue)
.Connection = conn
End If
End With
Dim adapter As New Data.SqlClient.SqlDataAdapter(cmd)
Try
conn.Open()
Dim ds As New Data.DataSet
adapter.Fill(ds)
GridView1.DataSource = ds
GridView1.DataBind()
Finally
conn.Close()
End Try
dropdown list to have "select a topic" to always appear when the drop
down loads. Now if a user selects a dropdown item it goes into the
datagrid fine, but if a user selects "select a topic" I get an error
message...
Error converting nvarchar to int on adapter.Fill(ds)
Here's the code behind can someone please assist? Thanks!
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
DropDownList2.SelectedIndexChanged
Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("TrainUserConnectionString").ConnectionString)
Dim cmd As New Data.SqlClient.SqlCommand
With cmd
.CommandType = Data.CommandType.StoredProcedure
.CommandText = "Getclassifications1"
If DropDownList2.SelectedValue = "select a topic" Then
Response.Write("Please select a topic")
Else
.Parameters.AddWithValue("classificationid",
DropDownList2.SelectedValue)
.Connection = conn
End If
End With
Dim adapter As New Data.SqlClient.SqlDataAdapter(cmd)
Try
conn.Open()
Dim ds As New Data.DataSet
adapter.Fill(ds)
GridView1.DataSource = ds
GridView1.DataBind()
Finally
conn.Close()
End Try