TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jane Omondi
NA
3
0
System.InvalidCastException: Specified cast is not valid.
Apr 7 2008 4:16 AM
Hi, I get the following error when i run my script and i dont know what the problem could be:
System.InvalidCastException: Specified cast is not valid.
at System.Data.SqlClient.SqlBuffer.get_Int32()
at System.Data.SqlClient.SqlDataReader.GetInt32(Int32 i)
Here is the code am running:
SqlConnection conn = new SqlConnection("server=(local);database=pubs;uid=admin;pwd=dbs4ever;");
string query = "select * from authors";
SqlCommand cmd = new SqlCommand(query, conn);
conn.Open();
SqlDataReader reader;
reader = cmd.ExecuteReader();
ArrayList response = new ArrayList();
while (reader.Read())
{
Authors author = new Authors();
author.au_id = reader.GetInt32(0);
author.au_lname = reader.GetString(1);
author.au_fname = reader.GetString(2);
response.Add(author);
}
reader.Close();
conn.Close();
return response;
}
public class Authors
{
public int au_id;
public string au_lname;
public string au_fname;
}
i will appreciate your help.
Reply
Answers (
4
)
"ValueChanged" event triggers before value changes, another bug in C#?
How to Display Data from Sql Server 2000 in windows application