|
 |
พอดีผมจะทำการบันทึกและก็แก้ไขด้วยครับ มี 2 ตาราง ตารางแรก [dbo].[ItCase] ผม Insert ทำได้ แต่พอแก้ไข ผมจะแก้ไข ตาราง Case ฟิล CaseType โดยแก้ไขผ่าน button เดียวกันต้องทำยังไงครับ |
|
 |
|
|
 |
 |
|
พอดีผมจะทำการบันทึกและก็แก้ไขด้วยครับ มี 2 ตาราง ตารางแรก [dbo].[ItCase] ผม Insert ทำได้ แต่พอแก้ไข ผมจะแก้ไข ตาราง Case ฟิล CaseType โดยแก้ไขผ่าน button เดียวกันต้องทำยังไงครับ
Code (C#)
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Test
{
public partial class TestEdit : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DateTime daValues = DateTime.Now;
string MyDt = daValues.ToString("yyyy-MM-dd HH:mm:ss");
TextBox7.Text = DateTime.Now.ToString(MyDt);
}
#region Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
if (DropDownList1.Text == "กำลังดำเนินการ")
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Myscript", "alert('บันทึกการแจ้งปัญหาไม่สำเร็จกรุณาใส่ ประเภทของปัญหา')", true);
}
if (Request.Form["Message"] == "")
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Myscript", "alert('บันทึกการแจ้งปัญหาไม่สำเร็จกรุณาใส่ รายละเอียดการแก้ไขปัญหา')", true);
}
else
{
SqlConnection conn = new SqlConnection("Data Source=ASD\\ASD2014;Initial Catalog=SvlITDB;User ID=it;Password=123456789");
conn.Open();
SqlCommand sqlcom = conn.CreateCommand();
sqlcom.CommandText = "INSERT INTO [dbo].[ItCase] ([CaseKey], [Solve], [StaffName], [CloseDT]) VALUES ('" + TextBox6.Text + "','" + Request.Form["Message"] + "', '" + DropDownList1.Text + "', '" + TextBox7.Text + "')";
//sqlcom.CommandText = "UPDATE[dbo].[Case] SET CaseStatusKey = '" + DropDownList2.Text + "' WHERE CaseKey = '" + TextBox1.Text + "' ";
//sqlcom.CommandText = "INSERT INTO[dbo].[CaseType] ( [CodeType], [NameType]) VALUES" + "('" + this.TextBox2.Text + "','" + TextBox3.Text + "')";
sqlcom.CommandType = CommandType.Text;
sqlcom.ExecuteNonQuery();
conn.Close();
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Myscript", "alert('บันทึกการแจ้งปัญหาสำเร็จ')", true);
}
}
#endregion
}
}
Tag : Web (ASP.NET), C#
|
|
 |
 |
 |
 |
Date :
2018-10-30 10:25:56 |
By :
wiraphon |
View :
733 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Update [Case] set CaseStatusKey = 1 where CaseKey = 1
ผมลอง Test คำสั่งได้ ใน SQL แต่ใน Visual C# ไม่ได้ครับ
|
 |
 |
 |
 |
Date :
2018-10-30 10:31:40 |
By :
wiraphon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ ใช้ตัวแปรส่งค่า 2 ตัวนะครับ Test ไปมาได้เลย ฝากเป็นความรู้ให้คนอื่นๆมาศึกษานะครับ
Code (C#)
SqlCommand sqlcom = conn.CreateCommand();
SqlCommand sqlcom2 = conn.CreateCommand();
sqlcom.CommandText = "INSERT INTO [dbo].[ItCase] ([CaseKey], [Solve], [StaffName], [CloseDT]) VALUES ('" + TextBox6.Text + "','" + Request.Form["Message"] + "', '" + DropDownList1.Text + "', '" + TextBox7.Text + "')";
sqlcom2.CommandText = "Update [Case] set CaseStatusKey = '" + DropDownList4.Text + "' where CaseKey = '" + TextBox6.Text + "'";
//sqlcom.CommandText = "INSERT INTO[dbo].[CaseType] ( [CodeType], [NameType]) VALUES" + "('" + this.TextBox2.Text + "','" + TextBox3.Text + "')";
sqlcom.CommandType = CommandType.Text;
sqlcom2.CommandType = CommandType.Text;
sqlcom2.ExecuteNonQuery();
sqlcom.ExecuteNonQuery();
conn.Close();
|
 |
 |
 |
 |
Date :
2018-10-30 10:58:24 |
By :
wiraphon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|