public void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
NowID = dataGridView1[dataGridView1.CurrentCell.RowIndex, 0].ToString().Trim();
if (gs != "")
{
SqlConnection str = new SqlConnection("server=127.0.0.1;uid=sa;pwd=sa;database=音乐库");
SqlCommand cmd = new SqlCommand("select top 1 * from " + gs + " where ID= '" + NowID + "'", str);
SqlDataReader sdr = null;
sdr = cmd.ExecuteReader();//读取数据
if (sdr != null)
{
if (sdr.Read())
{
gstextBox3.Text = sdr["格式"].ToString();
fgtextBox4.Text = sdr["风格"].ToString();
dztextBox5.Text = sdr["地址"].ToString();
bztextBox6.Text = sdr["备注"].ToString();
}
str.Close();
}
else { MessageBox.Show("读取的数据为空", "提示"); }
}
else { MessageBox.Show("请选择歌手名", "提示"); }
}
请问一下,我用以上的程序能将dataGridView中的数据显示在相应框中吗?