单击gridview后如何显示数据内容应显示在文本框,radiobutton,datetimepicker和listview中的数据库中 [英] How can i show data after clicking on the gridview the content should be display in textbox,radiobutton,datetimepicker and listview from database
问题描述
我写过这个,但不知道如何绑定单选按钮日期时间选择器等
private void dataGridView1_CellClick(object sender,DataGridViewCellEventArgs e)
{
SqlConnection con = new SqlConnection(data source = .; database = HMS; integrated Security = SSPI);
SqlDataAdapter adp = new SqlDataAdapter(select * from Doctor where Doctorid = ''+ dataGridView1.CurrentRow.Cells [Doctorid]。值+'',con);
DataSet ds = new DataSet();
adp .Fill(ds,Doctor);
txtDoctorId.Text = ds.Tables [Doctor]。行[0] [Doctorid]。ToString ();
txtFirstName.Text = ds.Tables [Doctor]。行[0] [Dfname]。ToString();
txtMiddleName.Text = ds.Tables [Doctor]。行[0] [Dmname]。ToString();
txtLastName.Text = ds.Tables [Doctor]。行[0] [ Dlname]。ToString();
string message = null;
if(ds.Tables [Doctor]。行[0] [Dgender]。ToString()==male)
{
message =male;
}
else
{
message =female;
}
rdoMale.Text = ds.Tables [Doctor]。行[0] [Dgender]。ToString( );
rdbFemale.Text = ds.Tables [Doctor]。行[0] [Dgender]。ToString();
txtPhoneNumber.Text = ds.Tables [Doctor]。行[0] []。ToString();
txtMobileNumber.Text = ds.Tables [Doctor]。行[0] []。ToString();
txtAddress.Text = ds.Tables [Doctor]。行[0] []。ToString();
txtEmailId.Text = ds.Tables [Doctor]。行[0] []。ToString();
txtSpecialization.Text = ds.Tables [Doctor ] .Rows [0] []。ToString();
}
您应该修复此代码,因为它将所有数据层内容放在表示层中。如果每个方法都有一个连接和一个连接字符串,你如何管理该字符串何时发生变化?
正如有人所说,你将来自数据库的值转换为适当的值,例如单选按钮的bools。
尝试为问题设置一个主题行来解释问题的性质,但不是整个问题
I have written this but dont know how to bind with radio button date time picker etc
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
SqlConnection con = new SqlConnection("data source=.; database=HMS; integrated Security=SSPI");
SqlDataAdapter adp = new SqlDataAdapter("select * from Doctor where Doctorid=''" + dataGridView1.CurrentRow.Cells["Doctorid"].Value + "''", con);
DataSet ds = new DataSet();
adp.Fill(ds,"Doctor");
txtDoctorId.Text = ds.Tables["Doctor"].Rows[0]["Doctorid"].ToString();
txtFirstName.Text = ds.Tables["Doctor"].Rows[0]["Dfname"].ToString();
txtMiddleName.Text = ds.Tables["Doctor"].Rows[0]["Dmname"].ToString();
txtLastName.Text = ds.Tables["Doctor"].Rows[0]["Dlname"].ToString();
string message = null;
if (ds.Tables["Doctor"].Rows[0]["Dgender"].ToString() == "male")
{
message = "male";
}
else
{
message = "female";
}
rdoMale.Text = ds.Tables["Doctor"].Rows[0]["Dgender"].ToString();
rdbFemale.Text = ds.Tables["Doctor"].Rows[0]["Dgender"].ToString();
txtPhoneNumber.Text = ds.Tables["Doctor"].Rows[0][""].ToString();
txtMobileNumber.Text = ds.Tables["Doctor"].Rows[0][""].ToString();
txtAddress.Text = ds.Tables["Doctor"].Rows[0][""].ToString();
txtEmailId.Text = ds.Tables["Doctor"].Rows[0][""].ToString();
txtSpecialization.Text = ds.Tables["Doctor"].Rows[0][""].ToString();
}
You should fix this code, because it''s putting all the data layer stuff right there in the presentation layer. If every method has a connection and a connection string, how do you manage when that string changes ?
As someone said, you turn the values coming from the DB in to values that are appropriate, like bools for radio buttons.
Try to have a subject line for your question that explains the NATURE of the question, but is not the whole question.
这篇关于单击gridview后如何显示数据内容应显示在文本框,radiobutton,datetimepicker和listview中的数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!