Connecting Tech Pros Worldwide Forums | Help | Site Map

It Gives Error While I am Inserting a Data in A table.???

Newbie
 
Join Date: Oct 2009
Posts: 2
#1: 4 Weeks Ago
hi frnz i have a table name Employee Master...it have a total 8 columns..

I want to insert a data of new employee in this table...I have created one form named addemp.aspx... for that.

i have written code for that..

Expand|Select|Wrap|Line Numbers
  1. SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Mydata.mdf;Integrated Security=True;User Instance=True");
  2.  
  3. SqlCommand cmd;
  4.  
  5. string str;
  6.  
  7.  
  8. protected void btnSignUp_Click(object sender, EventArgs e)
  9.     {
  10.          str = "insert into Employee Master values"+"('"+ txtempname + "','" + txtempcode + "','" + txtdepartment + "','" + txtcontactno + "','" + txtusername + "','" + txtpassword + "','" + txtemail + "')";
  11.  
  12.         cmd = new SqlCommand(str, con);
  13.         if (con.State == ConnectionState.Closed)
  14.             con.Open();
  15.        cmd.ExecuteNonQuery();
  16.  
  17.  
  18.  
  19.     }
bt when i m going to submit this from i get error...at runtime..

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'Master'.

so What is my mistakes..plz tell me how to insert This data..

ssnaik84's Avatar
Member
 
Join Date: Aug 2009
Location: Bengaluru, India
Posts: 124
#2: 4 Weeks Ago

re: It Gives Error While I am Inserting a Data in A table.???


Quote:
insert into Employee Master values
"Employee Master" should be single word.. should not contain "space"
Newbie
 
Join Date: Oct 2009
Posts: 2
#3: 4 Weeks Ago

re: It Gives Error While I am Inserting a Data in A table.???


my query was solved now.......frenz.....i have forget the add text property of the Textbox......so ....Thanx for your kind reply...by d way we can keep space in our Table name...in double Quatation Mark...
Reply