My requirement is to allow users to enter partno. in a text box.
There is a button called 'populate'. whenever the user enters a partno. and hits on populate button, the matching record from the database should show up on the screen. Each field in the databse got corresponding textboxes on the screen.
I have used the following code:
under Button_Click event,
Expand|Select|Wrap|Line Numbers
- SqlConnection MyConnection = new SqlConnection(Mysqlconnectionstring);
- MyConnection.Open();
- SqlCommand Cmd = new SqlCommand();
- Cmd.Connection = MyConnection;
- Cmd.CommandType = CommandType.Text ;
- Cmd.CommandText = "select * from database where Number = '+Partno.ToString ()'";
- SqlDataAdapter DA = new SqlDataAdapter(Cmd);
- DataSet DS = new DataSet();
- DA.Fill(DS);
- Partname.ToString() = DS.Tables[0].Rows[1][1].ToString();
- //all other fileds.
Expand|Select|Wrap|Line Numbers
- System.IndexOutOfRangeException
- There is no row at position 1.
Am I using any thing wrong here? Please advise.