Hi,
Can anyone send me common programming for insert,update and delete coding, which can automatically insert values into database , just by calling the class files in which this common codes are written.
Thanks in Advance,
A.Durga Prasad
Loading
Niradhip ChakrabortyPosted May 16, 2008, 2:14 PM
Update code:
string strSQL;
string s = "A1";
SqlConnection con1 = null;
con1 = new SqlConnection(ConfigurationManager.AppSettings["con"].ToString());
con1.Open();
strSQL = "Update CustomerSettings SET cus_vch_Id='"+s+"',cus_vch_CustomerName='" + txtCustomerName.Text + "',cus_vch_Address='" + txtAddress.Text + "',cus_vch_City='" + txtCity.Text + "',cus_vch_State='" + txtState.Text + "',cus_int_Zip=" + txtZip.Text + ",cus_vch_Telephone='" + txtTelephone.Text + "',cus_vch_Fax='" + txtFax.Text + "',cus_vch_Email='" + txtEmail.Text + "',cus_vch_WebsiteAddress='" + txtWebsite.Text + "',cus_vch_Options='" + rights + "'";
SqlCommand sqlComm = new SqlCommand(strSQL,con1);
sqlComm.ExecuteNonQuery();
sqlComm = null;
con1.Close();
con1 = null;
Delete code:
string strSQL;
SqlConnection con1 = null;
con1 = new SqlConnection(ConfigurationManager.AppSettings["con"].ToString());
con1.Open();
strSQL = "Delete from Users where usr_vch_name='"+txtUserName.Text+"'";
SqlCommand sqlComm = new SqlCommand(strSQL,con1);
sqlComm.ExecuteNonQuery();
con1.Close();
insert code:
SqlConnection con1 = null;
con1 = new SqlConnection(ConfigurationManager.AppSettings["con"].ToString());
con1.Open();
strSQL = "INSERT INTO Users (usr_vch_Name,usr_vch_Password,usr_int_Type,usr_vch_Rights,usr_dtm_Updated) Values ('" + txtUserName.Text + "','" + ncrypt + "',"+a+",'"+msgnew+"',"+System.DateTime.Now+")";
SqlCommand sqlComm = new SqlCommand(strSQL,con1);
sqlComm.ExecuteNonQuery();
sqlComm = null;
con1.Close();
Change the table name ,field name and control name as per your wish.
create an event for each operation or you also can create a class for each operation and call it
when it is required