Hi, yall. Am trying to update mysql table called exemptions with texts
in textboxes (txt......)but when i go back to the table, no changes is
made in the table. below is the code.
[code]
private void btnUpdate_Click(object sender, EventArgs e)
{
MySqlConnection mycon = new MySqlConnection("datasource=localhost;username=root;database=church");
MySqlCommand updatecom = new MySqlCommand("Update
exemptions set exemptions = '" + txtexempt.Text + "',exempt1='"
+ txtexempt1.Text + "',exempt2='" + txtexempt.Text + "' where ID ='" + txtmeid.Text + "'", mycon);
mycon.Open();
updatecom.ExecuteNonQuery();
mycon.Close();
MessageBox.Show("Member Id " + txtmeSname.Text + " has sucessfully been updated");
this.reset();
}
[/code]
Please someone tell me what to do
Loading
sandesh jPosted Nov 9, 2009, 5:42 AM
sample code..
CREATE PROCEDURE [dbo].[DepartmentMaster_Update]
(
@pkDeptID int,
@DeptName nvarchar(50)
)
AS
BEGIN
UPDATE DepartmentMaster SET DeptName=@DeptName
WHERE pkDeptID=@pkDeptID
END
After that you write code in update button
private void btnUpDate_Click(object sender, EventArgs e)
{
try
{
if (SID == 0)
{
MessageBox.Show("No record Exists", "DepartmentMaster", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (txtDeptName.Text == "")
{
MessageBox.Show("Please Choose Data for Update", "DepartmentMaster", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.txtDeptName.Focus();
}
else if (checkDuplicateUpdate() == true)
{
{
SqlCommand cmdUpdate = new SqlCommand("DepartmentMaster_Update", conn);
cmdUpdate.CommandType = CommandType.StoredProcedure;
cmdUpdate.Parameters.Add(new SqlParameter("@pkDeptID", SID));
cmdUpdate.Parameters.Add(new SqlParameter("@DeptName", txtDeptName.Text.Trim()));
conn.Open();
cmdUpdate.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Update Sucessful", "DepartmentMaster", MessageBoxButtons.OK, MessageBoxIcon.Information);
DataGridLoad();
clear();
}
}
}
catch (Exception ex1)
{
string strMsg = ex1.Message.ToString();
MessageBox.Show(strMsg, "DepartmentMaster", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
finally
{
if (conn.State.ToString() == "Open")
{
conn.Close();
}
}
}
sandesh jPosted Nov 9, 2009, 5:41 AM
sample code..
CREATE PROCEDURE [dbo].[DepartmentMaster_Update]
(
@pkDeptID int,
@DeptName nvarchar(50)
)
AS
BEGIN
UPDATE DepartmentMaster SET DeptName=@DeptName
WHERE pkDeptID=@pkDeptID
END
After that you write code in update button
private void btnUpDate_Click(object sender, EventArgs e)
{
try
{
if (SID == 0)
{
MessageBox.Show("No record Exists", "DepartmentMaster", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (txtDeptName.Text == "")
{
MessageBox.Show("Please Choose Data for Update", "DepartmentMaster", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.txtDeptName.Focus();
}
else if (checkDuplicateUpdate() == true)
{
{
SqlCommand cmdUpdate = new SqlCommand("DepartmentMaster_Update", conn);
cmdUpdate.CommandType = CommandType.StoredProcedure;
cmdUpdate.Parameters.Add(new SqlParameter("@pkDeptID", SID));
cmdUpdate.Parameters.Add(new SqlParameter("@DeptName", txtDeptName.Text.Trim()));
conn.Open();
cmdUpdate.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Update Sucessful", "DepartmentMaster", MessageBoxButtons.OK, MessageBoxIcon.Information);
DataGridLoad();
clear();
}
}
}
catch (Exception ex1)
{
string strMsg = ex1.Message.ToString();
MessageBox.Show(strMsg, "DepartmentMaster", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
finally
{
if (conn.State.ToString() == "Open")
{
conn.Close();
}
}
}