|
|
|
Update ข้อมูลใหม่ ไม่ได้น่ะค่ะ ใช้ asp.net กับ C# ค่ะ database เป็น sql server ค่ะ ช่วยหน่อยนะคะ |
|
|
|
|
|
|
|
พอใส่ค่าใหม่ลงไป click update แล้ว มันยังเอาค่าเก่ามาอ่ะค่ะ หรือว่าต้องใส่ตัวแปรใหม่ไปแทนอ่ะคะ นี่คือโค้ดตอน update อ่ะค่ะ
Code (C#)
protected void Button_Save_Click(object sender, EventArgs e)
{
DataSetCRMTableAdapters.AccountTableAdapter dsAccount = new DataSetCRMTableAdapters.AccountTableAdapter();
DataTable dtAccount = dsAccount.GetDataByCompanyID(intCompanyID);
if (dtAccount.Rows.Count > 0)
{
DataRow drViewAccount = dtAccount.Rows[0];
intAccountID = int.Parse(drViewAccount["AccountID"].ToString());
string CreditLimit = txtCreditLimit.Text.Trim();
string CreditDay = txtCreditDay.Text.Trim();
string PutBillDate = txtPutBillDate.Text.Trim();
string PutBillTime = txtPutBillTime.Text.Trim();
string PutBillPlace = txtPutBillPlace.Text.Trim();
string ReceiveCheckDate = txtReceiveCheckDate.Text.Trim();
string ReceiveCheckTime = txtReceiveCheckTime.Text.Trim();
string ReceiveCheckPlace = txtReceiveCheckPlace.Text.Trim();
string OrderCycle = txtOrderCycle.Text.Trim();
dsAccount.UpdateQuery(CreditLimit, CreditDay, intCompanyID, PutBillDate, PutBillTime, PutBillPlace, ReceiveCheckDate, ReceiveCheckTime, ReceiveCheckPlace, OrderCycle, intAccountID);
Response.Redirect("Account.aspx?SAOID=" + intSAOID + "&CompanyID=" + intCompanyID);
}
else
{
string CreditLimit = txtCreditLimit.Text.Trim();
string CreditDay = txtCreditDay.Text.Trim();
string PutBillDate = txtPutBillDate.Text.Trim();
string PutBillTime = txtPutBillTime.Text.Trim();
string PutBillPlace = txtPutBillPlace.Text.Trim();
string ReceiveCheckDate = txtReceiveCheckDate.Text.Trim();
string ReceiveCheckTime = txtReceiveCheckTime.Text.Trim();
string ReceiveCheckPlace = txtReceiveCheckPlace.Text.Trim();
string OrderCycle = txtOrderCycle.Text.Trim();
dsAccount.Insert(CreditLimit, CreditDay, intCompanyID, PutBillDate, PutBillTime, PutBillPlace, ReceiveCheckDate, ReceiveCheckTime, ReceiveCheckPlace, OrderCycle);
}
Tag : .NET, Ms SQL Server 2005, Web (ASP.NET), C#
|
|
|
|
|
|
Date :
2010-11-22 11:31:02 |
By :
เมย์ |
View :
1616 |
Reply :
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตอนที่กด Update มันน่าจะทำในส่วนของ Page_Load() และเรียกข้อมูลเดิมอีกครั้งหนึ่งน่ะครับ เลยได้แต่ข้อมูลเดิม ๆ
ซึ่งปกติแล้วหลาย ๆ คนจะรู้จัก
Code (C#)
if(!Page.IsPostBack())
{
// Bound Data
}
ASP.NET Page Life Cycle
หรือไม่ลอง Copy Source Code มาทั้งหมดน่ะครับ จะได้ช่วยดูครับ หรือไม่ลองดูตัวอย่างการ Update ข้อมูลได้ที่
Go to : (C#) ASP.NET SQL Server Edit/Update Record
|
|
|
|
|
Date :
2010-11-22 11:43:47 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
นี่ค่ะ source ทั้งหมด
Code (C#)
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Account_Account : System.Web.UI.Page
{
public int intSAOID, intCompanyID, intAccountID;
protected void Page_Load(object sender, EventArgs e)
{
if ((String)Session["Username"] == null)
{
Response.Redirect("http://192.168.1.20/CRM/Warning.aspx");
}
else
{
if (Request.QueryString["SAOID"] != null || Request.QueryString["CompanyID"] != null) // receive value from View_Computer.aspx page
{
intSAOID = Int32.Parse(Request.QueryString["SAOID"]);
intCompanyID = Int32.Parse(Request.QueryString["CompanyID"]);
txtbox.Text = intSAOID.ToString(); /// for pass value
txtbox2.Text = intCompanyID.ToString(); /// for pass value
}
DataSetCRMTableAdapters.CompanyTableAdapter dsCompany = new DataSetCRMTableAdapters.CompanyTableAdapter();
DataTable dtCompany = dsCompany.GetDataByCompanyID(intCompanyID);
DataRow drCompany = dtCompany.Rows[0];
lbCompanyName.Text = drCompany["CompanyName"].ToString();
DataSetCRMTableAdapters.AccountTableAdapter dtAccount = new DataSetCRMTableAdapters.AccountTableAdapter();
DataTable dsAccount = dtAccount.GetDataByCompanyID(intCompanyID);
if (dsAccount.Rows.Count > 0)
{
DataRow drAccount = dsAccount.Rows[0];
txtCreditLimit.Text = drAccount["CreditLimit"].ToString();
txtCreditDay.Text = drAccount["CreditDay"].ToString();
txtPutBillDate.Text = drAccount["PutBillDate"].ToString();
txtPutBillPlace.Text = drAccount["PutBillPlace"].ToString();
txtPutBillTime.Text = drAccount["PutBillTime"].ToString();
txtReceiveCheckDate.Text = drAccount["ReceiveCheckDate"].ToString();
txtReceiveCheckPlace.Text = drAccount["ReceiveCheckPlace"].ToString();
txtReceiveCheckTime.Text = drAccount["ReceiveCheckTime"].ToString();
txtOrderCycle.Text = drAccount["OrderCycle"].ToString();
}
}
}
protected void Button_Save_Click(object sender, EventArgs e)
{
DataSetCRMTableAdapters.AccountTableAdapter dsAccount = new DataSetCRMTableAdapters.AccountTableAdapter();
DataTable dtAccount = dsAccount.GetDataByCompanyID(intCompanyID);
if (dtAccount.Rows.Count > 0)
{
DataRow drViewAccount = dtAccount.Rows[0];
intAccountID = int.Parse(drViewAccount["AccountID"].ToString());
string CreditLimit = txtCreditLimit.Text.Trim();
string CreditDay = txtCreditDay.Text.Trim();
string PutBillDate = txtPutBillDate.Text.Trim();
string PutBillTime = txtPutBillTime.Text.Trim();
string PutBillPlace = txtPutBillPlace.Text.Trim();
string ReceiveCheckDate = txtReceiveCheckDate.Text.Trim();
string ReceiveCheckTime = txtReceiveCheckTime.Text.Trim();
string ReceiveCheckPlace = txtReceiveCheckPlace.Text.Trim();
string OrderCycle = txtOrderCycle.Text.Trim();
dsAccount.UpdateQuery(CreditLimit, CreditDay, intCompanyID, PutBillDate, PutBillTime, PutBillPlace, ReceiveCheckDate, ReceiveCheckTime, ReceiveCheckPlace, OrderCycle, intAccountID);
Response.Redirect("Account.aspx?SAOID=" + intSAOID + "&CompanyID=" + intCompanyID);
}
else
{
string CreditLimit = txtCreditLimit.Text.Trim();
string CreditDay = txtCreditDay.Text.Trim();
string PutBillDate = txtPutBillDate.Text.Trim();
string PutBillTime = txtPutBillTime.Text.Trim();
string PutBillPlace = txtPutBillPlace.Text.Trim();
string ReceiveCheckDate = txtReceiveCheckDate.Text.Trim();
string ReceiveCheckTime = txtReceiveCheckTime.Text.Trim();
string ReceiveCheckPlace = txtReceiveCheckPlace.Text.Trim();
string OrderCycle = txtOrderCycle.Text.Trim();
dsAccount.Insert(CreditLimit, CreditDay, intCompanyID, PutBillDate, PutBillTime, PutBillPlace, ReceiveCheckDate, ReceiveCheckTime, ReceiveCheckPlace, OrderCycle);
}
}
protected void Button_Back_Click(object sender, EventArgs e)
{
}
protected void txtCreditLimit_TextChanged(object sender, EventArgs e)
{
}
}
|
|
|
|
|
Date :
2010-11-22 11:50:08 |
By :
เมย์ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แล้วจะแก้ไขได้ยังไงอ่ะค่ะ
|
|
|
|
|
Date :
2010-11-22 11:58:22 |
By :
เมย์ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
protected void Page_Load(object sender, EventArgs e)
{
if ((String)Session["Username"] == null)
{
Response.Redirect("http://192.168.1.20/CRM/Warning.aspx");
}
else
{
if (Request.QueryString["SAOID"] != null || Request.QueryString["CompanyID"] != null) // receive value from View_Computer.aspx page
{
intSAOID = Int32.Parse(Request.QueryString["SAOID"]);
intCompanyID = Int32.Parse(Request.QueryString["CompanyID"]);
txtbox.Text = intSAOID.ToString(); /// for pass value
txtbox2.Text = intCompanyID.ToString(); /// for pass value
}
if(!Page.IsPostBack)
{
DataSetCRMTableAdapters.CompanyTableAdapter dsCompany = new DataSetCRMTableAdapters.CompanyTableAdapter();
DataTable dtCompany = dsCompany.GetDataByCompanyID(intCompanyID);
DataRow drCompany = dtCompany.Rows[0];
lbCompanyName.Text = drCompany["CompanyName"].ToString();
DataSetCRMTableAdapters.AccountTableAdapter dtAccount = new DataSetCRMTableAdapters.AccountTableAdapter();
DataTable dsAccount = dtAccount.GetDataByCompanyID(intCompanyID);
if (dsAccount.Rows.Count > 0)
{
DataRow drAccount = dsAccount.Rows[0];
txtCreditLimit.Text = drAccount["CreditLimit"].ToString();
txtCreditDay.Text = drAccount["CreditDay"].ToString();
txtPutBillDate.Text = drAccount["PutBillDate"].ToString();
txtPutBillPlace.Text = drAccount["PutBillPlace"].ToString();
txtPutBillTime.Text = drAccount["PutBillTime"].ToString();
txtReceiveCheckDate.Text = drAccount["ReceiveCheckDate"].ToString();
txtReceiveCheckPlace.Text = drAccount["ReceiveCheckPlace"].ToString();
txtReceiveCheckTime.Text = drAccount["ReceiveCheckTime"].ToString();
txtOrderCycle.Text = drAccount["OrderCycle"].ToString();
}
}
}
}
น่าจะตรงนี้ครับ ผมแก้ตรง if(!Page.IsPostBack)
|
|
|
|
|
Date :
2010-11-22 12:39:06 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อย่าลืมสมัครสมาชิกดด้วยน่ะครับ
|
|
|
|
|
Date :
2010-11-22 13:12:22 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากนะคะ update ได้แล้วค่ะ เย้ ๆ
|
|
|
|
|
Date :
2010-11-22 13:20:34 |
By :
เมย์ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|