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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • niravdarji85
    New Member
    • Oct 2009
    • 2

    #1

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

    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..

    Code:
    SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Mydata.mdf;Integrated Security=True;User Instance=True");
        
    SqlCommand cmd;
        
    string str;
    
    
    protected void btnSignUp_Click(object sender, EventArgs e)
        {
             str = "insert into Employee Master values"+"('"+ txtempname + "','" + txtempcode + "','" + txtdepartment + "','" + txtcontactno + "','" + txtusername + "','" + txtpassword + "','" + txtemail + "')";
    
            cmd = new SqlCommand(str, con);
            if (con.State == ConnectionState.Closed)
                con.Open();
           cmd.ExecuteNonQuery();
        
    
    
        }
    bt when i m going to submit this from i get error...at runtime..

    Exception Details: System.Data.Sql Client.SqlExcep tion: Incorrect syntax near 'Master'.

    so What is my mistakes..plz tell me how to insert This data..
    Last edited by Frinavale; Nov 3 '09, 04:58 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • ssnaik84
    New Member
    • Aug 2009
    • 149

    #2
    insert into Employee Master values
    "Employee Master" should be single word.. should not contain "space"

    Comment

    • niravdarji85
      New Member
      • Oct 2009
      • 2

      #3
      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...

      Comment

      Working...