J
Jason Huang
Hi,
I need to update my data based on the textboxes input on my windows form.
But I feel the following sql requery is to long and cumbersome.
Is there some more convient way to do the Update thing?
Thanks for help.
Jason
Here are some of my codes:
public void UpdateData(string strUpdateQry)
{
mConn=new SqlConnection(gstrConn);//new connection need to be here first
mConn.Open();
mComm=new SqlCommand(strUpdateQry,mConn);
mTrans = mConn.BeginTransaction();
mComm.Transaction=mTrans;
try
{
mComm.ExecuteReader();
mTrans.Commit();
}
catch(SqlException e)
{
mTrans.Rollback();
}
mConn.Close();
}//UpdateData
string strUpdate="INSERT INTO Contact (CustNo,Serial,Contact,";
strUpdate += "ContactDept, ContactTitle, ContactPhone,";
strUpdate += "ContactPhoneExt, ContactCellPhone, ContactFax,";
strUpdate += "Email) VALUES (";
strUpdate += "'" +m_iCustNo+ "', ";
strUpdate += "'" +txtSerial.Text+ "', ";
strUpdate += "'" +txtContact.Text+ "', ";
strUpdate += "'" +txtContactDept.Text+ "', ";
strUpdate += "'" +txtContactTitle.Text+ "', ";
strUpdate += "'" +txtContactPhone.Text+ "', ";
strUpdate += "'" +txtContactPhoneExt.Text+ "', ";
strUpdate += "'" +txtContactCellPhone.Text+ "', ";
strUpdate += "'" +txtContactFax.Text+ "', ";
strUpdate += "'" +txtEmail.Text+ "') ";
this.UpdateData(strUpdate);
I need to update my data based on the textboxes input on my windows form.
But I feel the following sql requery is to long and cumbersome.
Is there some more convient way to do the Update thing?
Thanks for help.
Jason
Here are some of my codes:
public void UpdateData(string strUpdateQry)
{
mConn=new SqlConnection(gstrConn);//new connection need to be here first
mConn.Open();
mComm=new SqlCommand(strUpdateQry,mConn);
mTrans = mConn.BeginTransaction();
mComm.Transaction=mTrans;
try
{
mComm.ExecuteReader();
mTrans.Commit();
}
catch(SqlException e)
{
mTrans.Rollback();
}
mConn.Close();
}//UpdateData
string strUpdate="INSERT INTO Contact (CustNo,Serial,Contact,";
strUpdate += "ContactDept, ContactTitle, ContactPhone,";
strUpdate += "ContactPhoneExt, ContactCellPhone, ContactFax,";
strUpdate += "Email) VALUES (";
strUpdate += "'" +m_iCustNo+ "', ";
strUpdate += "'" +txtSerial.Text+ "', ";
strUpdate += "'" +txtContact.Text+ "', ";
strUpdate += "'" +txtContactDept.Text+ "', ";
strUpdate += "'" +txtContactTitle.Text+ "', ";
strUpdate += "'" +txtContactPhone.Text+ "', ";
strUpdate += "'" +txtContactPhoneExt.Text+ "', ";
strUpdate += "'" +txtContactCellPhone.Text+ "', ";
strUpdate += "'" +txtContactFax.Text+ "', ";
strUpdate += "'" +txtEmail.Text+ "') ";
this.UpdateData(strUpdate);