I have an app with a DAL and so far I have been calling sprocs that require no input parameters and all works fine. I now have to call a sproc with requires an input paramter. The sproc I am calling is as follows: ALTER PROCEDURE dbo.prc_QA_SysCodes_sel_drop_fill ( @sysCodeType as int ) As BEGIN DECLARE @Err Int SELECT A.[SysCodeID], A.[SysCodeDesc] FROM [Contract].[dbo].[QA_SysCodes] A WHERE A.SysCodeType = @sysCodeType order by A.[SortOrder], A.[SysCodeID] Set @Err = @@Error RETURN @Err End I need to pass in the @sysCodeType but can't figure out how to pass it to the sproc. Thoughts, words of wisdom? -- modified at 13:16 Tuesday 27th June, 2006
IMC2006
Posts
-
Stored proc call - passing a parameter [modified] -
Getting data from a grid to a dataset to save [modified]Perfect it was the cmd.CommandType = CommandType.StoredProcedure line that I was missing... thanks!
-
System.Data.DBConcurrencyExceptionI have a app with a grid and am working on updating data from the grid to the data base. the update is triggered off a menu item. the code is as follows: try { // New data entered to Contract QA_Setup table DataAccess da = new DataAccess(); string sproc = "prc_QA_Setup_upd"; string dbAction = "Update"; string tableName = "QA_Setup"; // Update to find grid changes //ug.Update(); ug.UpdateData(); // to retrieve ds with modified rows to grid ds.GetChanges(DataRowState.Modified); // Call to DAL to update QA_Setup with new data da.updateDB(ds, sproc, dbAction, tableName); } This passes to the DAL and tries to run: private void prepareUpdate(string sproc, string tableName) { // Create parameters for the QA_Setup dataset via Sqlcommand SqlCommand cmd = new SqlCommand(sproc, conn); // call set cmd properties defineParams(tableName, cmd); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = sproc; //RunProc(sproc); //RunProc(cmd); dap.UpdateCommand = cmd; } However I get a System.Data.DBConcurrencyException, what am I missing?
-
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
-
Retrieving connection string from app.configI am building a C# window app and am trying to 1. Create a DataAccess class which retrievs the connection string from app.config and then 2. call the DataAccess from a form load. I have successfully created the DataAccess.cs class but am having difficulties creating the retrieval of the app.config connection string. Does anyone have suggestions or a GOOD site with a simple C# example of how to do this.
-
Sample app with DAL connectivity [modified]I have data access/population of a grid via drag and drop but now I am trying to create a data access layer with provided stored procs to populate grids as opposed to drag and drop. So my issue is creating a DATAAccess class with the SQLConnection to be called by various forms.. then once the SQLConnection is made I need to call storeProc1 for example. So 1. I need an example of a generic dataaccess class to create the connection 2. be able to call the dataaccess from a from 3. be able to call a stored proc to populate a GRID
-
Sample app with DAL connectivity [modified]I am working on an app and having issues with my DAL and connectivity. Can anyone suggest a site with a sample app which details how to do this? Guess this might help... using VS.NET2005 in conjunction with SQL2K5 -- modified at 14:37 Monday 5th June, 2006
-
if else for forms displayed [modified]I tried this but still it does not function correctly. If formA is not visible then it open a new instance no problem. the problem is if I go back and try and open it again, instead of selecting the previously opened form, it opens a new instance via formA.Show() even though copy of formA is open. If I change visible == true, then it believes an instance is already opened even though one is not opened. if (formA.Visible == false) { // shows new formA form formA.Show(); MessageBox.Show("New Form"); } else { // Reset focus to currently opened form formA.Select(); MessageBox.Show("Reset Focus to form"); }
-
if else for forms displayed [modified]I am creating a new window app and am having difficulty with resetting focus to a form instead of opening multiple instances of the form. I have a menu to open formA for example from the MainForm menu. I want to have the logic be something like (from click of menu from MainForm) If formA visiblity == true then { set focus to formA} else { formA.show} I can't seem to get the syntax for the if condition and the set focus command back to formA if it is already open. Any help would be appreciated, thanks! :confused: -- modified at 1:07 Saturday 27th May, 2006
-
Browser display issueHow can I change my browser setting so that I don't have to scroll horizontally. Some site display correct while other I have to scroll.