Working on three tier in c# but my insert query is not working -


access layer:

public bool addstudent(string busstudentfullname, string busstudentfathername) {     con = new sqlceconnection();     con.connectionstring = "data source = c:\\users\\hasni\\documents\\visual studio 2010\\projects\\universitymanagementsystem\\universitymanagementsystem\\universitydb.sdf";     con.open();      ds1 = new dataset();     //datatable t = new datatable();     // string sql = "select * adminpassword admin name ='" + adminnamelogintextbox.text + "' , password='" + passwordlogintextbox.text + "'";     //string qry = "select * students";      // string sql = "select * adminpassword admin name ='" + adminnamelogintextbox.text + "' , password='" + passwordlogintextbox.text + "'";     string sql = "select * students";       da = new sqlcedataadapter(sql, con);     //da = new sqlcedataadapter();      //datatable t = new datatable();     //da.fill(t);     da.fill(ds1, "students");       //string usernamedb = convert.tostring(ds1.tables[0]);     // return usernamedb;      con.close();    // string busstudentfullname;     //string busstudentfathername;     string sql2 = "insert students (student full name,student father name) values('"+ busstudentfullname + "','" + busstudentfathername + "')";       da = new sqlcedataadapter(sql2, con);     da.fill(ds1, "students");      con.close();     return true;  } 

business layer:

public bool getresponseforaddstudent(string studentname, string studentfathername) {     bool var = access.addstudent(studentname, studentfathername);     return var; } 

presentation layer:

private void addstudentbutton_click(object sender, eventargs e) {     string studentname = studentnamebox.text;     string studentfathername = stdfathernamebox.text;      bool var = _busgeneral.getresponseforlogin(studentname, studentfathername);      if (var)     {         messagebox.show("student added");     }     else      {         messagebox.show("sorry");     } } 

your sql isn't valid, when columns have spaces in name need surround square brackets:
insert students (student full name,student father name)
instead needs
insert students ([student full name],[student father name])


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -