I was working on C# windows application as front end and SQL as back end I have display my sql table data in dtatgridview.
I want to display the data in textbox whatever row i select in datagridview.
I have write some code but its not showing data in textboxes.
here is my code:
the code is on datagridview cellcontentclick event
cn.ConnectionString = "Data Source=sam-AB59A9C19;Initial Catalog=master;Integrated Security=True";
cn.Open();
SqlCommand cmd = new SqlCommand();
SqlDataReader rdr;
string cd = dataGridView1.SelectedRows.ToString();
string CommandText = "select * from acc where id=@id";
cmd = new SqlCommand(CommandText);
cmd.Connection = cn;
cmd.Parameters.Add(new SqlParameter("@id", System.Data.SqlDbType.VarChar, 20, "id"));
cmd.Parameters["@id"].Value = dataGridView1.SelectedRows.ToString();
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
textBox1.Text = rdr["id"].ToString();
textBox2.Text = rdr["sub"].ToString();
textBox3.Text = rdr["marks"].ToString();
}
cn.Close();
the code does not display any error message.