Hell frirends
I have to two fields customer ID and Customer Name. I have written the procedure to insert records as follows:
PROCEDURE [dbo].[InsertCustomer] ( @Cust_code int, @Cust_Name varchar(20) ) AS INSERT INTO Users VALUES(@Cust_code, @Cust_Name)
Now I am calling from the c# to insert a value
SqlConnection Conn = new SqlConnection(ConfigurationSettings.AppSettings["Buy4nowConnectionString"].ToString()); Conn.Open();
SqlCommand _cmd = new SqlCommand("procSelectUserGroup", Conn);
_cmd.CommandType = CommandType.StoredProcedure; _cmd.Parameters.AddWithValue("@InsertCustomer", "1,'test'"); SqlDataReader _reader = _cmd.ExecuteReader();
Please let me know, what I have to do to insert record (Now I am inserting this record directly)
If I add two controls in my ASP page as customer ID, cusotmer name,
how should I substitute. Please help me
My connection string working properly.
My advance thanks
|
| Author: Ritesh N. Jain 28 Aug 2008 | Member Level: Gold | Rating: Points: 6 |
change below line
_cmd.Parameters.AddWithValue("@InsertCustomer", "1,'test'");
with
_cmd.Parameters.AddWithValue("@Cust_code", tbCustCode.text); _cmd.Parameters.AddWithValue("@Cust_Name ", tbCustName.text);
|
| Author: ANIL PANDEY 29 Aug 2008 | Member Level: Diamond | Rating: Points: 6 |
hi,
u can try this
PROCEDURE [dbo].[InsertCustomer] ( @Cust_code int, @Cust_Name varchar(20) ) AS INSERT INTO Users VALUES(@Cust_code, @Cust_Name)
Now I am calling from the c# to insert a value
SqlConnection Conn = new SqlConnection(ConfigurationSettings.AppSettings["Buy4nowConnectionString"].ToString()); Conn.Open();
SqlCommand _cmd = new SqlCommand("procSelectUserGroup", Conn);
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.Parameters.AddWithValue("@Cust_code", tbCustCode.text); _cmd.Parameters.AddWithValue("@Cust_Name ", tbCustName.text); SqlDataReader _reader = _cmd.ExecuteReader();
Thanks Anil
|