Hi,
I'm trying to get the data from the database.
For that i build one stored procedure as
ALTER Procedure [dbo].[Select_Students](@Sno int = null)
As
Begin
If @Sno Is Null
Select Sno,Sname,Class,Fees From Stud
Else
Select Sname,Class,Fees From Stud Where Sno=@Sno
End
And the code under get button as
private void button1_Click(object sender, EventArgs e)
{
cmd.Parameters.Clear();
ds = new DataSet();
da = new SqlDataAdapter();
cmd.CommandText = "Select_Students";
da = new SqlDataAdapter(cmd);
da.Fill(ds, "Stu");
string value_of_sno = textBox1.Text;
cmd.Parameters.Add("@sno", value_of_sno);
if (ds.Tables[0].Rows.Count > 0)
{
textBox2.Text = ds.Tables[0].Rows[0][1].ToString();
textBox3.Text = ds.Tables[0].Rows[0][2].ToString();
textBox4.Text = ds.Tables[0].Rows[0][3].ToString();
}
else
MessageBox.Show("Record Not Existed");
}
But always i'm getting the first record values only.
I think textBox2.Text = ds.Tables[0].Rows[0][1].ToString();
textBox3.Text = ds.Tables[0].Rows[0][2].ToString();
textBox4.Text = ds.Tables[0].Rows[0][3].ToString();
due to this code only i'm getting the first record values.
can one help me to get the record values depending on the value entered by me in the first textbox.