**my Store procedure:**
USE [DB_COUNTERINTELLIGENCE] GO /****** Object: StoredProcedure [dbo].[Updatederogatory] Script Date: 2015/6/12 1:21:24 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- ============================================= ALTER PROCEDURE [dbo].[Updatederogatory] @ID int, @txtid int, @Firstname varchar(30), @Middlename varchar(30), @Lastname varchar(30), @Company varchar(50), @Department varchar(40), @Position varchar(40), @Violation text, @DateCommitted date, @TimeCommitted nchar(10), @Remarks text, @Activities text, @Violation2 text, @DateCommitted2 date, @TimeCommitted2 nchar(10), @Remarks2 text, @Activities2 text, @Violation3 text, @DateCommitted3 date, @TimeCommitted3 nchar(10), @Remarks3 text, @Activities3 text, @Images image AS BEGIN SET NOCOUNT ON;
UPDATE tbl_derogatory SET Firstname = @Firstname,Middlename = @ Middlename,Lastname = @ Lastname,Company = @ Company,Department = @Department,Position = @Position,Violation = @Violation, DateCommitted = @DateCommitted,TimeCommitted = @TimeCommitted, 备注= @Remarks,Activities = @Activities,Violation2 = @ Violation2,DateCommitted2 = @ DateCommitted2,TimeCommitted2 = @TimeCommitted2,Remarks2 = @ Remarks2,Activities2 = @ Activities2, Violation3 = @ Violation3,DateCommitted3 = @ DateCommitted3, TimeCommitted3 = @ TimeCommitted3,Remarks3 = @ Remarks3,Activities3 = @ Activities3,Images = @Images WHERE ID = @txtid END
**Here is my code:**
> if (txtid.Text == "")
> {
> MessageBox.Show("Require ID is a must, Please Registered again for your ID", "ERROR", MessageBoxButtons.OK,
> MessageBoxIcon.Error);
> }
> else if (txtfirstname.Text == "")
> {
> MessageBox.Show("Your name is missing", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
>
> }
> else if (txtlastname.Text == "")
> {
> MessageBox.Show("Your Last name is missing", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
> }
> else if (txtmiddlename.Text == "")
> {
> MessageBox.Show("Your Middle name is missing", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
> }
> else
> {
> try
> {
> byte[] img = null;
> FileStream fs = new FileStream(imageLocation, FileMode.Open, FileAccess.Read);
> BinaryReader br = new BinaryReader(fs);
> img = br.ReadBytes((int)fs.Length);
>
> SqlConnection con = new SqlConnection(cs);
> SqlCommand cmd = new SqlCommand();
> cmd.Connection = con;
> cmd.CommandType = CommandType.StoredProcedure;
> cmd.CommandText = "Updatederogatory";
> cmd.Parameters.AddWithValue("@ID", txtid.Text);
> cmd.Parameters.AddWithValue("@Firstname", txtfirstname.Text);
> cmd.Parameters.AddWithValue("@Middlename", txtmiddlename.Text);
> cmd.Parameters.AddWithValue("@Lastname", txtlastname.Text);
> cmd.Parameters.AddWithValue("@Company", combocompany.Text);
> cmd.Parameters.AddWithValue("@Department", comboDepartment.Text);
> cmd.Parameters.AddWithValue("@Position", txtposition.Text);
>
> cmd.Parameters.AddWithValue("@Violation", richviolation.Text);
> cmd.Parameters.AddWithValue("@DateCommitted ", datecommitted.MaxDate);
> cmd.Parameters.AddWithValue("@TimeCommitted", timecommitted.Text);
> cmd.Parameters.AddWithValue("@Remarks", richremarks.Text);
> cmd.Parameters.AddWithValue("@Activities", richderoactivities.Text);
>
> cmd.Parameters.AddWithValue("@Violation2", richviolation2.Text);
> cmd.Parameters.AddWithValue("@DateCommitted2", datecommitted2.MaxDate);
> cmd.Parameters.AddWithValue("@TimeCommitted2", timecommitted2.Text);
> cmd.Parameters.AddWithValue("@Remarks2", richremarks2.Text);
> cmd.Parameters.AddWithValue("@Activities2", richactivities2.Text);
>
> cmd.Parameters.AddWithValue("@Violation3", richviolation2.Text);
> cmd.Parameters.AddWithValue("@DateCommitted3", datecommitted2.MaxDate);
> cmd.Parameters.AddWithValue("@TimeCommitted3", timecommitted2.Text);
> cmd.Parameters.AddWithValue("@Remarks3", richremarks2.Text);
> cmd.Parameters.AddWithValue("@Activities3", richactivities3.Text);
> con.Open();
> cmd.Parameters.Add(new SqlParameter("@Images", img));
> cmd.ExecuteNonQuery();
> con.Close();
> MessageBox.Show("Successfully Updated");
> }
> catch (Exception ex)
> {
>
> MessageBox.Show(ex.Message);
> }
}
我的问题是,当我点击更新按钮时,将弹出消息框并写入错误&#34;空路径名称不合法&#34; ..
如何解决这个问题?
答案 0 :(得分:0)
错误是由于变量&#34; imageLocation&#34;尚未初始化。
答案 1 :(得分:0)
我认为问题出在这一行:
FileStream fs = new FileStream(imageLocation, FileMode.Open, FileAccess.Read);
你可能没有imageLocation