none
I want to know the code to do modifications in the database(SQL SERVER2005) table by using C# STORED Procedures RRS feed

  • Question

  • I want to know the code for updating the database SQL Server 2005 using C# .Net

    with the help of stored procedures

    Tuesday, July 17, 2007 10:19 AM

Answers

  • Well it's a massive subject but off the top of my head.

     

    You need a SqlConnection object

     

    SqlConnection sqlConn = new SqlConnection("Connection string here")

     

    You need a SqlCommand object

     

    SqlCommand sqlComm = new SqlCommand(sqlConn,"Name of stored procedure"); <-- not sure if I have signature right way round the ide will help you through it.

     

    sqlComm.CommandType = CommandType.StoredProcedure

     

    Does your procedure take parameters?

     

    SqlParameter sqlParam = new SqlParameter("parametername is stored proc", paramValue);

     

    sqlComm.Paramaters.Add(sqlParam);

     

    try

    {

    sqlComm.Connection.Open();

    sqlComm.ExecuteNonQuery();

    }

    catch ......

     

    Hope you can get what you need out of it.

     

    If you want results back like a dataset you will then need to use ExecuteReader instead, I think in .net2.0 teh datatable object or dataset can take a reader to create a dataset/datatable.

     

    1.1 you have to do it yourself and note the created dataset is read only since we used a reader.

    Tuesday, July 17, 2007 11:42 AM