473,666 Members | 2,237 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_S electedIndexCha nged(ByVal sender As
Object, ByVal e As System.EventArg s) Handles
DropDownList2.S electedIndexCha nged
Dim conn As New
Data.SqlClient. SqlConnection(C onfigurationMan ager.Connection Strings("TrainU serConnectionSt ring").Connecti onString)

Dim cmd As New Data.SqlClient. SqlCommand

With cmd
.CommandType = Data.CommandTyp e.StoredProcedu re

.CommandText = "Getclassificat ions1"
If DropDownList2.S electedValue = "select a topic" Then

Response.Write( "Please select a topic")

Else
.Parameters.Add WithValue("clas sificationid",
DropDownList2.S electedValue)
.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.DataS ource = ds

GridView1.DataB ind()

Finally

conn.Close()

End Try
Jan 8 '08 #1
2 1436
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 "classification id" n so passing the
error messg..

just a guess..

On Jan 8, 8:30*pm, JJ297 <nc...@yahoo.co mwrote:
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_S electedIndexCha nged(ByVal sender As
Object, ByVal e As System.EventArg s) Handles
DropDownList2.S electedIndexCha nged

* * * * Dim conn As New
Data.SqlClient. SqlConnection(C onfigurationMan ager.Connection Strings("TrainU *serConnectionS tring").Connect ionString)

* * * * Dim cmd As New Data.SqlClient. SqlCommand

* * * * With cmd
* * * * * * .CommandType = Data.CommandTyp e.StoredProcedu re

* * * * * * .CommandText = "Getclassificat ions1"

* * * * * * If DropDownList2.S electedValue = "select a topic" Then

* * * * * * * * Response.Write( "Please select a topic")

* * * * * * Else
* * * * * * * * .Parameters.Add WithValue("clas sificationid",
DropDownList2.S electedValue)
* * * * * * * * .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.DataS ource = ds

* * * * * * GridView1.DataB ind()

* * * * Finally

* * * * * * conn.Close()

* * * * End Try
Jan 8 '08 #2
On Jan 8, 11:53*am, smhusain1...@gm ail.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 "classification id" n so passing the
error messg..

just a guess..

On Jan 8, 8:30*pm, JJ297 <nc...@yahoo.co mwrote:
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_S electedIndexCha nged(ByVal sender As
Object, ByVal e As System.EventArg s) Handles
DropDownList2.S electedIndexCha nged
* * * * Dim conn As New
Data.SqlClient. SqlConnection(C onfigurationMan ager.Connection Strings("TrainU **serConnection String").Connec tionString)
* * * * Dim cmd As New Data.SqlClient. SqlCommand
* * * * With cmd
* * * * * * .CommandType = Data.CommandTyp e.StoredProcedu re
* * * * * * .CommandText = "Getclassificat ions1"
* * * * * * If DropDownList2.S electedValue = "select a topic" Then
* * * * * * * * Response.Write( "Please select a topic")
* * * * * * Else
* * * * * * * * .Parameters.Add WithValue("clas sificationid",
DropDownList2.S electedValue)
* * * * * * * * .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.DataS ource = ds
* * * * * * GridView1.DataB ind()
* * * * 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.S electedItem.Val ue = "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
4545
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 set to...it is set to false. Can someone show me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am doing the following:
5
11892
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 dropdown list control does not retain its SelectedValue. Unless I read the SelectedValue right after the control has been loaded, populated, and assigned with its original value (and of course that is
0
1387
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 perform some actions. The postback is not happening due to this error on the page. All the dropdown lists on this page cause this error, but I use dropdowns on many other pages that do not have any problems. Any ideas??? *** Sent via...
3
3520
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 based on the values selected on both the dropdown lists. But this part is not working. It picks up right value for the first dropdown list and always takes the FIRST value of the second dropdown list. I am not sure how to make it use the selected value...
1
2662
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 main list) to open up the full listing (sublist) below that headline. My JavaScript is almost but not quite working as needed. It also serves up an error that an object "has no properties". The particular error message and line of code it refers to:...
3
2799
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 these choices will call another dropdown list box when one of the choices from the first gets selected. (I hope this makes sense) All of this is being done on a single form. I know how to make a (sub) dropdown list not seen before the action...
5
6649
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 according to selection made in first dropdown list and it will also come from ms-access database.(for example if i am selecting country as india in first dropdown list then in second dropdown list will show states of india) the problem is that i...
16
2415
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 'Display Quick Dropdown ListBox If ixQuickLevel = 0 Then Exit Sub Forms!fAAA.cboQuick = Forms!fAAA.cboQuick.DefaultValue Forms!fAAA.cboQuick.ListRows = ixQuickCount Forms!fAAA.cboQuick.SetFocus Forms!fAAA.cboQuick.Dropdown ...
16
10587
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 Dropdown is opened it requeries Cbo2 to ListIndex = 0. But I also want it to close (unselect, undrop list) Cbo2 & open (select, dropdown) Cbo1 on MsgBox error. This insures the user selects property of Cbo1 first. Private Sub...
0
8355
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.