Getstring Question

Feb 11, 2004

how can i add two columns in each row (both strings) in a table only using getstring?





i'm getting an error from this statement... thanks





dim row as string





while dr.read()





problem with this statment





------->> row = dr.getstring(1) + dr.getstring(2)





end while

View 6 Replies


ADVERTISEMENT

Using ExecuteReader() And GetString()

Mar 3, 2008

Hi.
I'm trying to read data from a database. This is my code:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
connection.Open();SqlCommand cmd = new SqlCommand(sql, connection);
myReader = cmd.ExecuteReader();if (myReader.Read())
{
name1TextBox.Text = myReader.GetString(1);
addr1TextBox.Text = myReader.GetString(2);
code1TextBox.Text = myReader.GetString(5);
tel1TextBox.Text = myReader.GetString(6);
fax1TextBox.Text = myReader.GetString(7);
:
:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The above code works fine until one of the GetString calls trys to return NULL (in this case myReader.GetString(5)).
In other words, this code will run through about 30 rows of data until it runs in to a NULL entry for one of the columns.
At that stage it's too late. I'm not allowed call GetString( ) on a NULL value.
Is there anyway I can test the column entry before calling GetString( ).
Regards (& thanks in advance)
Garrett

View 4 Replies View Related

GetString Got Cast Error

Apr 1, 2008

I used SQLDataReader to assign a OrderID to a text box.
OrderID is varchar type. I got cast error. How to fix it?
Me.txtOrderID.Text = myDataReader.GetString("OrderID")

View 6 Replies View Related

Question About SqlDataReader.GetString

Nov 3, 2004

In my database I have this code:
Do While sqlDataReader.Read()
lblTitle.InnerText = sqlDataReader.GetString(2)
Loop

And this will get my sql's 3rd column ( its #2 because its 0-indexed ), but I am throwing this error when I try to print this sqlDataReader.GetString(2) if this particular value is a int. How do I cast it to a String.

I have already done these two things:
sqlDataReader.GetString(2).ToString()
&
CStr(sqlDataReader.GetString(2))

????

j

View 2 Replies View Related

Using SqlDataReader.GetString When Value In Database Might Be A NULL

Jun 8, 2007

I am currently using the following code to populate fields in a form  EditUserNotes.Text = EditUserReader.GetString(2); which works just fine (the datatype in the database is 'text') as long as the data stored in the database is not null.  If the data is null, I get the error: Data is Null. This method or property cannot be called on Null values. which is really annoying as there are times when the data stored in the database is legitimately NULLI can use the following code to fix the problem, but it seems less elegant  EditUserNotes.Text = EditUserReader.GetValue(2).ToString() is there really a difference between the GetString and the GetValue(x).ToString() methods or are they interchangeable?     

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved