如何在c#中更新我的数据库访问

时间:2017-02-07 07:53:22

标签: c# sql sql-server-2008 tsql

这是我的代码

private void btnUpdate_Click(object sender, EventArgs e)
{
   byte[] imgbyte = null;
   FileStream fs = new FileStream(this.txtImageLocation.Text, FileMode.Open, FileAccess.Read);
   BinaryReader br = new BinaryReader(fs);
   imgbyte = br.ReadBytes((int)fs.Length);

   connection.Open();
   string query = "update [Student] set [StudentID] = @StudentID, [Lastname] = @Lastname, [Firstname] = @Firstname, [Image] = @Image where [NID] = '" +lblNID.Text+ "' "; //NID column is my primary key and auto increment

   OleDbCommand command = new OleDbCommand(query, conn);

   command.Parameters.AddWithValue("@StudentID", txtStudentID.Text);
   command.Parameters.AddWithValue("@Lastname", txtStudentLN.Text);
   command.Parameters.AddWithValue("@Firstname", txtStudentFN.Text);
   command.Parameters.Add(new OleDbParameter("@Image", imgbyte));
}

每当我尝试更新而不更改图片时,我都会收到错误:空路径不合法

当我尝试更改图片时,我在条件表达式

中收到了数据类型不匹配的错误 有人能帮帮我吗?提前谢谢!

这是表格 enter image description here

0 个答案:

没有答案