Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
4
Reply
System.InvalidCastException: Specified cast is not valid.
Jane Omondi
Apr 7 2008 4:16 AM
38.1k
Reply
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.
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
"ValueChanged" event triggers before value changes, another bug in C#?
How to Display Data from Sql Server 2000 in windows application