Click here to Skip to main content
15,911,707 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using(SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ToString()))
            {
                SqlCommand cmd = new SqlCommand("proc_Customers", con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter cname = new SqlParameter("@CustomerName", txtcname.Text);
                SqlParameter clocation = new SqlParameter("@CustomerLocation", txtclocation.Text);
                SqlParameter cgender = new SqlParameter("@Gender", ddlgender.Text);
                SqlParameter caddress = new SqlParameter("@CustomerAddress", txtcaddress.Text);
                SqlParameter cphonenumber = new SqlParameter("@PhoneNumber",txtphonenumber.Text);
                SqlParameter cemailid=new SqlParameter("@EmailId",txtemailid.Text);

                
                cmd.Parameters.Add(cname);
                cmd.Parameters.Add(clocation);
                cmd.Parameters.Add(cgender);
                cmd.Parameters.Add(caddress);
                cmd.Parameters.Add(cphonenumber);
                cmd.Parameters.Add(cemailid);
                con.Open();
                cmd.ExecuteNonQuery();
Posted
Updated 10-Mar-15 18:55pm
v2
Comments
Which line?
Faisalabadians 11-Mar-15 3:52am    
Could you show connection string "DBCS" ? well, DBCS is Double-byte Character Sets and I am wondering if this messing up with your connection string name.

have a look https://msdn.microsoft.com/en-us/library/windows/desktop/dd317794%28v=vs.85%29.aspx
Stephen Hewison 11-Mar-15 4:43am    
One what line do you get the error? con.Open or cmd.Exec. Based on the error I'm guessing it's con.Open in which case you'll have something in your connection string. Other's have seen this by trying to escape quotes using ".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900