 |
|
เป็นในส่วนของ form edit ครับ ถ้าเปิด record นั้นขึ้นมา แล้วไม่ได้มีการเปลี่ยนรูป
พอกด submit จะ error ทันทีเลยครับ มันโฟกัส บรรทัด File.Copy(sourceFile, destFile, true);

Code (C#)
private void bntsubmit_Click_1(object sender, EventArgs e)
{
string bow = "bowbo";
string sourceFile = path + "\\" + filenname;
//ดึงพาธปัจจุบันที่โปรแกรม exe รันอยู่ ไปต่อด้วยชื่อโฟลเดอร์ Picture เพื่อเก็บภาพ และพาธเป็นปลายทาง
string pathPicture = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Picture";
//destFile ไฟล์ปลายทาง ที่จะ copy ไปวาง ได้แก่ พาธปลายทาง และชื่อไฟล์
string destFile = pathPicture + "\\" + filenname;
//ทำกการตรวจสอบ พาธเป็นปลายทาง
if (!Directory.Exists(pathPicture))
Directory.CreateDirectory(pathPicture);//ถ้ายังไม่เคยมีในโลก ให้สร้างใหม่
//ทำการตรวจสอบ ไฟล์ปลายทาง
if (!File.Exists(destFile))
// File.Copy(sourceFile,@destFile);//ถ้ายังไม่มีให้ copy ไปได้
//หรือใช้
File.Copy(sourceFile, destFile, true);//จะ copy ทับของเก่า
// connect database from class connection
SqlConnection myConnection = default(SqlConnection);
connection NewConnection = new connection();
NewConnection.Connection_Today();
connection.myConnection.Open();
// command for select/insert/update/dalete
SqlCommand myCommand = connection.myConnection.CreateCommand();
myCommand.CommandText = "UPDATE customer SET " + " custcode = '" + this.txtcustcode.Text + "' , custgroupcode = '" + this.txtcustgroupcode.SelectedValue + "', startdate = '" + this.txtstartdate.Value + "' , taxid = '" + this.txttaxid.Text + "' , taxrequired = '" + taxq + "', custstatuscode = '" + this.txtcuststatuscode.SelectedValue + "',remark = '" + this.txtremark.Text + "', lastupdate = '" + DateTime.Now + "', updateby = '" + bow + "', image = '" + destFile + "' " + " WHERE custcode = '" + Strcustcode + "' ";
myCommand.CommandType = CommandType.Text;
myCommand.ExecuteNonQuery();
connection.myConnection.Close();
// close connect database
MessageBox.Show("Update Successfully");
this.Hide();
Customer f = new Customer();
f.Show();
}
Tag : .NET, Ms SQL Server 2008, Win (Windows App), C#, Windows
|
|
 |
 |
 |
 |
Date :
2014-02-26 10:20:21 |
By :
flintstone |
View :
1097 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |