473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Error with dropdown list

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").Con nectionString)

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
Jan 8 '08 #1
2 1423
Hi,
I m a c# developer..dont have idea abt vb.net syntax but
the problem seems to be in If Condition..
seems like every time control passing in else condition n so passing
nvarchar value "select a topic" to ur procedure
which takes only int value for ID "classificationid" n so passing the
error messg..

just a guess..

On Jan 8, 8:30*pm, JJ297 <nc...@yahoo.comwrote:
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("TrainU*serConnectionString").Co nnectionString)

* * * * 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
Jan 8 '08 #2
On Jan 8, 11:53*am, smhusain1...@gmail.com wrote:
Hi,
I m a c# developer..dont have idea abt vb.net syntax but
the problem seems to be in If Condition..
seems like every time control passing in else condition n so passing
nvarchar value "select a topic" to ur procedure
which takes only int value for ID "classificationid" n so passing the
error messg..

just a guess..

On Jan 8, 8:30*pm, JJ297 <nc...@yahoo.comwrote:
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("TrainU**serConnectionString").C onnectionString)
* * * * 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- Hide quoted text -

- Show quoted text -
Actually I solved it by adding List Item value = 0 on the asp page.
Then on the aspx page I added
If DropDownList2.SelectedItem.Value = "0" Then
DD2.Text = ("select a topic")
End If

It works!
Jan 8 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
0
by: DCC700 | last post by:
After converting a web application to 2005, I am receiving an invalid character error when I change the value in a dropdown list. The dropdown list is set to postback on selected index changed and...
3
by: er1 | last post by:
Hi all, I have created a double dropdown list. Based on the first list selection, second list populates (this works fine). I have a submit button, which when clicked should run a select query...
1
by: luispunchy | last post by:
I have an accordion style dropdown list/sublist menu (functions similar to the "today on WebMD video" widget found on http://www.webmd.com/) - it will allow users to click on a headline (from the...
3
by: fish919 | last post by:
Hello All, I am creating a date base in access. I want to create a dropdown list box that is connected to another dropdown list box. You start with a dropdown list that has 5 choices and each of...
5
by: abhi3211 | last post by:
i am using java inside java script page. in that page i want to use two dropdown list. in first dropdown list i am getting data from ms-access database. in second dropdown list i want to get data...
16
by: OldBirdman | last post by:
This code is in a Module called from an _Click event for my form named fAAA. Variables beginning ix... are Global Long, declared elsewhere. Public Sub QuickShow() On Error GoTo QuickShow_Error...
16
by: AFSSkier | last post by:
I have several cascading ComboBoxes & would like to close Cbo2 & open Cbo1 when there is an error. These CboBoxes are on an Excel spreadsheet, not a UserForm. I have the following code, if the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.