Getting data from a grid to a dataset to save [modified]
-
I am working on getting data out of a datagrid, and save it to a SQL data base. I have the following code: // Create parameters for the QA_Setup dataset via Sqlcommand SqlCommand cmd = new SqlCommand(); // Define the params for each column in QA_SetUp // cmd.Parameters.Add("@CompanyName", SqlDbType.VarChar, 50, ds.Tables("CompanyName").column("CompanyName")); cmd.Parameters.Add("@CompanyName", SqlDbType.VarChar, 50, "CompanyName"); cmd.Parameters.Add("@CompanyCode", SqlDbType.VarChar, 50, "CompanyCode"); cmd.Parameters.Add("@InspectionPrefix", SqlDbType.VarChar, 50, "InspectionPrefix"); cmd.Parameters.Add("@TestPrefix", SqlDbType.VarChar, 50, "TestPrefix"); cmd.Parameters.Add("@DefectPrefix", SqlDbType.VarChar, 50, "DefectPrefix"); cmd.Parameters.Add("@AuditTrail", SqlDbType.Bit, 1, "AuditTrail"); //define connection and stored proc name cmd.Connection = conn; cmd.CommandText = sproc; // call insert command for the cmd dap.InsertCommand = cmd; When I run the app I and try and save I get a syntax error(System.Data.SQLClient.SQLException) as follows: Line1: Incorrect Syntax near 'prc_QA_Setup_ins'. This is the sproc name that is passed in. Not sure what my issue is, any idea? the sproc is declared as string sproc="prc_QA_Setup_ins"; which is passed over to my DAL which is where the code above resides. -- modified at 21:52 Tuesday 13th June, 2006
-
I am working on getting data out of a datagrid, and save it to a SQL data base. I have the following code: // Create parameters for the QA_Setup dataset via Sqlcommand SqlCommand cmd = new SqlCommand(); // Define the params for each column in QA_SetUp // cmd.Parameters.Add("@CompanyName", SqlDbType.VarChar, 50, ds.Tables("CompanyName").column("CompanyName")); cmd.Parameters.Add("@CompanyName", SqlDbType.VarChar, 50, "CompanyName"); cmd.Parameters.Add("@CompanyCode", SqlDbType.VarChar, 50, "CompanyCode"); cmd.Parameters.Add("@InspectionPrefix", SqlDbType.VarChar, 50, "InspectionPrefix"); cmd.Parameters.Add("@TestPrefix", SqlDbType.VarChar, 50, "TestPrefix"); cmd.Parameters.Add("@DefectPrefix", SqlDbType.VarChar, 50, "DefectPrefix"); cmd.Parameters.Add("@AuditTrail", SqlDbType.Bit, 1, "AuditTrail"); //define connection and stored proc name cmd.Connection = conn; cmd.CommandText = sproc; // call insert command for the cmd dap.InsertCommand = cmd; When I run the app I and try and save I get a syntax error(System.Data.SQLClient.SQLException) as follows: Line1: Incorrect Syntax near 'prc_QA_Setup_ins'. This is the sproc name that is passed in. Not sure what my issue is, any idea? the sproc is declared as string sproc="prc_QA_Setup_ins"; which is passed over to my DAL which is where the code above resides. -- modified at 21:52 Tuesday 13th June, 2006
IMC2006 wrote:
Line1: Incorrect Syntax near 'prc_QA_Setup_ins'.
Well, the code snippet that you provide doesn't even mention a stored procedure name - So, I'm guessing you've not provided all the necessary code to diagnose your problem. I am therefore guessing that somewhere you have a
cmd.CommandText = "prc_QA_Setup_ins"
And all you are missing is
cmd.CommandType = CommandType.StoredProcedure
Scottish Developers upcoming sessions include: .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy My: Website | Blog
-
IMC2006 wrote:
Line1: Incorrect Syntax near 'prc_QA_Setup_ins'.
Well, the code snippet that you provide doesn't even mention a stored procedure name - So, I'm guessing you've not provided all the necessary code to diagnose your problem. I am therefore guessing that somewhere you have a
cmd.CommandText = "prc_QA_Setup_ins"
And all you are missing is
cmd.CommandType = CommandType.StoredProcedure
Scottish Developers upcoming sessions include: .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy My: Website | Blog