string querySql = "Select Admission_Date,Name,Father_name,Date_of_birth,NIC_No,Present_Adress,Age,Contact_No,Weight,Height,Image from Admform WHERE Member_ID=@memid";
using (SqlConnection conSql = new SqlConnection("Data Source=azeem;Initial Catalog=ittihadgym;Integrated Security=True"))
{
using (SqlCommand command = new SqlCommand(querySql, conSql))
{
conSql.Open();
command.Parameters.AddWithValue("@memid", textBoxmember.Text);
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
dateTimePicker1.Value=reader[0].ToString();
textBoxname.Text = reader[1].ToString();
textBoxfname.Text = reader[2].ToString();
dateTimePicker2.Value=reader[3].ToString();
textBoxnic.Text = reader[4].ToString();
textBoxadress.Text=reader[5].ToString();
textBoxage.Text=reader[6].ToString();
textBoxcntct.Text=reader[7].ToString();
textBoxweight.Text=reader[8].ToString();
textBoxheight.Text=reader[9].ToString();
byte[] img = (byte[])(reader[10]);
if (img == null)
pictureBox1.Image = null;
else
{
MemoryStream ms = new MemoryStream(img);
pictureBox1.Image = Image.FromStream(ms);
}
}
else
{
MessageBox.Show("This is does not exist.");
cn.Close();
答案 0 :(得分:0)
应该是
dateTimePicker1.Value = Convert.ToDateTime(reader[0]);
dateTimePicker2.Value = Convert.ToDateTime(reader[3]);
因为DateTimePicker.Value
属性设置或获取所选DateTime
。因此,它需要DateTime
而不是string
。