如题,我用
{
SqlConnection con = new SqlConnection("server=.;database=dxdata;uid=sa;pwd= ");
string sql = "select * from 表名 where ID = '" + this.textBox1.Text + "'";
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
try
{
adapter.Fill(ds, "表名");
if (ds.Tables[0].Rows.Count > 0)
{
textBox3.Text = ds.Tables[0].Rows[0]["字段名1"].ToString();
textBox4.Text = ds.Tables[0].Rows[0]["字段名2"].ToString();
comboBox1.字段名3
dateTimePicker1字段名4
}
else
{
MessageBox.Show("没有相关记录");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
数据表中的记录都是varchar 如何将 字段名3 的值赋值给combox 将字段名4的值赋给dateTimePicker1呢
{
SqlConnection con = new SqlConnection("server=.;database=dxdata;uid=sa;pwd= ");
string sql = "select * from 表名 where ID = '" + this.textBox1.Text + "'";
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
try
{
adapter.Fill(ds, "表名");
if (ds.Tables[0].Rows.Count > 0)
{
textBox3.Text = ds.Tables[0].Rows[0]["字段名1"].ToString();
textBox4.Text = ds.Tables[0].Rows[0]["字段名2"].ToString();
comboBox1.字段名3
dateTimePicker1字段名4
}
else
{
MessageBox.Show("没有相关记录");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
数据表中的记录都是varchar 如何将 字段名3 的值赋值给combox 将字段名4的值赋给dateTimePicker1呢
ComboBox.Text ?
DateTimePicker.Value ?
是要这样吗?
dateTimePicker1.Value = ds.Tables[0].Rows[0]["日期"].Todate();直接用这样的话 就会报错
dateTimePicker1.Value =DataTime.Pase(ds.Tables[0].Rows[0]["日期"].ToString());