Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 有人能告诉我为什么datetimepicker在数据检索时出错吗?_C# - Fatal编程技术网

C# 有人能告诉我为什么datetimepicker在数据检索时出错吗?

C# 有人能告诉我为什么datetimepicker在数据检索时出错吗?,c#,C#,应该是 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 Cat

应该是

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();

因为它
DateTimePicker.Value
属性设置或获取所选的
DateTime
。因此,它需要一个
DateTime
而不是
string

您得到了什么错误以及在哪里?datetimepicker1,value=reader[0]。Tostring();这里我得到了错误的代码什么是错误??请尝试学习基本的第一。你必须把它转换成datetime。你们两个都很棒:)thnks..我的代码现在运行得很好特别感谢你提供dateHappy的额外信息来帮助@Mynameiskan。BTW另一种表示感谢的方式可能是你可以投票,如果这个或任何答案已经解决了你的问题,请通过点击复选标记来考虑。这向更广泛的社区表明,你已经找到了一个解决方案,并给回答者和你自己带来了一些声誉。没有义务这样做。
dateTimePicker1.Value = Convert.ToDateTime(reader[0]);
dateTimePicker2.Value = Convert.ToDateTime(reader[3]);