Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
Retrieve related data through id in text boxes ?
Usama Shaikh
Feb 25 2016 8:54 AM
321
Reply
i want to retrieve data into text boxes through id or name. im using this code:
public partial class Form3 : Form
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
//SqlDataAdapter sqlda;
//DataSet ds;
string str;
private void button4_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.Open();
str = "select * from Department where Code='" + codeTextBox.Text.Trim() + "'";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
if (reader.Read())
{
dep_NameTextBox.Text = reader["Name"].ToString();
dep_TypeTextBox.Text = reader["Dep_Type"].ToString();
//TextBox4.Text = reader["ADDRESS"].ToString();
//TextBox5.Text = reader["PHNO"].ToString();
//TextBox6.Text = reader["STATE"].ToString();
reader.Close();
con.Close();
}
When i run the program it generate the error:
An unhandled exception of type 'System.NullReferenceException' occurred in voucher.exe
Additional information: Object reference not set to an instance of an object.
how to resolve it?
or how to retrieve related id data in text boxes in other query ?
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
No overload for method ' ' takes 8/11 arguments
Trouble to serialize XML with classes and a list