This is a discussion on SQLError within the ASP and ASP.NET Programming forums, part of the Web Development category; I tried to insert a value in a sql database through ASP.NET(C#). There is no error. But while ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| I tried to insert a value in a sql database through ASP.NET(C#). There is no error. But while executing the application a error occurs on the ExecuteNonQuery() statement. The error is : Incorrect syntax near '12' The source code is : public void addproject(int bid) { try{ DateTime schedule; int project_id,budget; string title, desc, type, priority, remarks; SqlDataAdapter sqladapter = new SqlDataAdapter("select * from project_details", sqlcon); sqladapter.Fill(ds, "project_details"); project_id = ds.Tables[0].Rows.Count; project_id += 1; title = add_title.Text; desc = add_description.Text; budget = int.Parse(add_budget.Text); schedule = DateTime.Parse(add_schedule.Text); type = add_type.Text; priority = add_priority.Text; remarks = add_remarks.Text; SqlCommand cmd = new SqlCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "INSERT into project_details (Project_id,Title,Description,Building_ID,Outline_ budget,Outline_schedule,Type,Priority,Remarks) VALUES (" + project_id + ",'" + title + "','" + desc + "'," + bid + "," + budget + "," + schedule + ",'" + type + "','" + priority + "','" + remarks + "')"; cmd.Connection = sqlcon; sqlcon.Open(); cmd.ExecuteNonQuery(); } catch (Exception ex) { Response.Write(ex.Message); } } |
| Sponsored Links |
| |||
| check the insert statement in debug mode...get the sql from commandtext property and run it in SQL Server ... |
![]() |
| Thread Tools | |
| Display Modes | |
| |