473,387 Members | 1,516 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,387 software developers and data experts.

SqlDataReader.GetInt32 problem

1
I'm using this method to populate a comboBox directly from the db but when i execute i get this error: InvalidCastException was unhandled.Specified cast is not valid.

here is the method.
private void buildcboAuthors()
{
string strQuery = "Select k.Name as State_Name from States k where k.Name_ID=19 or k.Name_ID=17 or k.Name_ID=20 or k.Name_ID=11 or k.Komuna_ID=04";

SqlCommand cmd = new SqlCommand(strQuery, sqlConn);

this.sqlConn.Open();
SqlDataReader dtRead = cmd.ExecuteReader();
ArrayList Komuna = new ArrayList();
while (dtRead.Read())
{
Komuna.Add(new AddValue(dtRead.GetString(1), dtRead.GetInt32(0)));

}
dtRead.Close();
this.sqlConn.Close();
this.cmbStates.DataSource = Komuna;
this.cmbStates.DisplayMember = "View";
this.cmbStates.ValueMember = "Value";

}
what am I doing wrong ???

can anyone help me
regards devi
Sep 20 '11 #1
1 2514
PianoMan64
374 Expert 256MB
Trying adding a .ToString() to the end of the GetInt32() Method
Expand|Select|Wrap|Line Numbers
  1.      Komuna.Add(new AddValue(dtRead.GetString(1),
  2.                 dtRead.GetInt32(0).ToString()));
  3.  
Sep 21 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: PeteZ | last post by:
I'm having a problem where I exec a stored procedure (which SELECTs all rows from a table, which has 100 rows) - each row has 8 columns. When I exec the code (see below) I get 8 in...
2
by: Matthias S. | last post by:
Hi, I've written a simple app which should just fetch some data from a database and render the results into a ListView. In order to not freeze the GUI, I'm using a BackgroundWorker. The...
5
by: Tom Edelbrok | last post by:
I notice that using the SqlDataReader requires the use of ordinal field references rather than by name. For example, do while (myDataReader.Read())...
5
by: Chad | last post by:
I want to create a class which contains a date, integer and string property which all allow a NULL value. I don't want to store the values in an Object datatype. I prefer more strongly typed...
13
by: lithoman | last post by:
I'm stumped here. I run the procedure Batch_Select against the database with @ID=18 and I get the expected data. When it loads into a SqlDataReader, it gets messed up somehow. Initially, after the...
3
by: Frank Milverckowitz | last post by:
Hi, Newbie question about SqlDataReader column value access... In java jdbc code to get a value from a table column we can pass the column name (instead of an int index or offset): String...
4
by: Prem | last post by:
This is what I am trying to do double utmx = (double) (pSqlReader.GetValue(pSqlReader.GetOrdinal("UTM_X83"))); and this is the exception that I get System.InvalidCastException was unhandled...
4
by: nayla | last post by:
I am using 2 SqlDataReader and while(dr.Read()) get only first record and loop stops. its not retriving all of the records but if I comment db1.RunSQLStatement(sql1,out unit_dr); while...
6
by: dgleeson3 | last post by:
Hello All I have VB code (.Net 2005) reading from an SQL server 2005 database. Im getting InvalidCastException when doing reader.GetInt32(0) Im simply reading an int from a simple database. It...
3
by: Dom | last post by:
Still teaching myself about SQLDataReader and associated classes. I have to say, the new HELP screens from MS are just about useless!! Let's assume I have just read some records from a table...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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,...

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.