|
|
|
C# SQL Server จะ UPDATE 2 ตาราง ทำอย่างไงหรอครับ ?? |
|
|
|
|
|
|
|
จะ UPDATE 2 ตาราง ทำอย่างไงหรอครับ ??
Code (C#)
{
strSQL = "UPDATE CreateSchedule SET " +
" ScheduleID = '" + this.txtId.Text + "' " +
" ,NameSchedule = '" + this.txtnameSc.Text + "' " +
" ,Date = '" + this.txtDate.Text + "' " +
" ,StartTime = '" + this.ddlTime1.SelectedItem.Value + "' " +
" ,EndTime = '" + this.ddlTime2.SelectedItem.Value + "' " +
" ,Location = '" + this.txtlocation.Text + "' " +
" ,Boss = '" + this.ddlBoss.SelectedItem.Value + "' " +
" ,Name = '" + this.txtNC.Text + "' " +
" ,Tel = '" + this.txttel.Text + "' " +
" WHERE ScheduleID = '" + Request.QueryString["ScheduleID"] + "' ";
objCmd = new SqlCommand();
objCmd.Connection = objConn;
objCmd.CommandText = strSQL;
objCmd.CommandType = CommandType.Text;
try
{
objCmd.ExecuteNonQuery();
this.lblStatus.Text = "Record Updated";
this.lblStatus.Visible = true;
}
catch (Exception ex)
{
this.lblStatus.Text = "Record can not update";
}
}
Tag : .NET, Ms SQL Server 2005, Web (ASP.NET), C#
|
|
|
|
|
|
Date :
2013-06-24 21:12:40 |
By :
Kaen17 |
View :
1183 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เขียน Query ขึ้นมาอีกชุดครับ แต่ถ้าต้องการความถูกต้องให้ใช้พวก Transaction เข้ามาช่วยก็ดีครับ
|
|
|
|
|
Date :
2013-06-25 06:04:07 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับผม ได้ละครับ
Code (C#)
{
strSQL = "UPDATE CreateSchedule SET " +
" ScheduleID = '" + this.txtId.Text + "' " +
" ,NameSchedule = '" + this.txtnameSc.Text + "' " +
" ,Date = '" + this.txtDate.Text + "' " +
" ,StartTime = '" + this.ddlTime1.SelectedItem.Value + "' " +
" ,EndTime = '" + this.ddlTime2.SelectedItem.Value + "' " +
" ,Location = '" + this.txtlocation.Text + "' " +
" ,Boss = '" + this.ddlBoss.SelectedItem.Value + "' " +
" ,Name = '" + this.txtNC.Text + "' " +
" ,Tel = '" + this.txttel.Text + "' " +
" WHERE ScheduleID = '" + Request.QueryString["ScheduleID"] + "' ";
objCmd = new SqlCommand();
objCmd.Connection = objConn;
objCmd.CommandText = strSQL;
objCmd.CommandType = CommandType.Text;
objCmd.ExecuteNonQuery();
strSQL = "UPDATE totalWork SET " +
" workID = '" + this.txtId.Text + "' " +
" ,workName = '" + this.txtnameSc.Text + "' " +
" ,workdate = '" + this.txtDate.Text + "' " +
" ,worktime = '" + this.ddlTime1.SelectedItem.Value + "' " +
" ,worktime2 = '" + this.ddlTime2.SelectedItem.Value + "' " +
" ,worklocation = '" + this.txtlocation.Text + "' " +
" ,workboss = '" + this.ddlBoss.SelectedItem.Value + "' " +
" WHERE workID = '" + Request.QueryString["ScheduleID"] + "' ";
objCmd = new SqlCommand();
objCmd.Connection = objConn;
objCmd.CommandText = strSQL;
objCmd.CommandType = CommandType.Text;
objCmd.ExecuteNonQuery();
try
{
this.lblStatus.Text = "Record Updated";
this.lblStatus.Visible = true;
}
catch (Exception ex)
{
this.lblStatus.Text = "Record can not update";
}
}
เเล้วถ้าเราจะได้มันเด้งเเจ้งเตือนว่าบันทึกสำเร็จทำอย่างไรรึครับ?
|
|
|
|
|
Date :
2013-06-25 10:08:08 |
By :
Kaen17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2013-06-25 16:46:56 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|