How to Update Database using HashTable
i have wrote a code in CRUD class
public static int Data_IUD(string proc, Hashtable ht)
{
int res = 0;
try
{
//Main Connection class SqlCommand cmd = new SqlCommand(proc, Main.con);
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString);
SqlCommand cmd = new SqlCommand(proc, con);
cmd.CommandType = CommandType.StoredProcedure;
foreach (DictionaryEntry item in ht)
{
cmd.Parameters.AddWithValue(item.Key.ToString(), item.Value);
}
con.Open();
res = cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return res;
}
using this i am trying to update the data. for this purpose, i wrote the following code behind the update button
public static int edit = 0;
private void btnEdit_Click(object sender, EventArgs e)
{
edit = 1;
if (edit == 1)
{
//MessageBox.Show("Yes: " + edit);
Hashtable ht = new Hashtable();
ht.Add("@Name", txtName.Text.Trim());
ht.Add("@Addr", txtAddress.Text.Trim());
ht.Add("@id", CompID);
/*foreach (string key in htb.Keys)
{
MessageBox.Show(String.Format("{0}: {1}", key, htb[key]));
}*/
if (SqlCrud.Data_IUD("sp_Company_Updates", ht) > 0)
{
Main.showMessage(txtName.Text + " Updated successfully", "Success");
LoadData();
}
else
{
Main.showMessage("Unable to update record", "Error");
}
}
}
it is not updating the database. store procedure is
Create PROCEDURE[dbo].[sp_Company_Update]
@Name nvarchar(50),
@Addr nvarchar(250),
@ID int
AS
Update tblCompany
set
[Name]=@Name,
[Address]=@Addr
where
[ID]=@ID
how to get solution???