none
Simple C#.NET code needed. ASAP ! RRS feed

  • Question

  • Hello,

    I am a SQL Programmer in need of a simple C# Console Application.

     

    Basically, I want a C#.NET code that will do the following:

     

    1.Query a sql table and return the results in the form of a dataset. The query is as simple as 'Select DNIS from Phone'

     

    2.Update a SQL table using the result of the previous query.

    The update statement is 'Update Redirect_Number Set Number = DNIS'

     

    Thank you.

     

     

     

     

     

    Thursday, March 27, 2008 11:11 PM

All replies

  • There are myriads of myriads of examples out there and there are search engines that can find them.

     

    My personal opinion is that it is rude to post such questions here.

     

    EX: http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.aspx

    http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx

    http://www.daniweb.com/forums/thread21636.html

     

    Thursday, March 27, 2008 11:33 PM
  • What you need is a C#/.NET developer but here is a bit of help. What you need is

     

    1. get data from sql table

    2. iterate the results in DataTable if there are multipe DNIS and insert one per call. If there so many, then you want a different solution.

     

    Here is the code exmple of update the table:

     

    string sqlConnectionString = "";

    string sprocName = "";

    string paramName = "";

    string paramValue = "";

    SqlDbType paramDataType= \\datatype of your choice;

    string errMessage = "";

     

    //update

    using (SqlConnection conn = new SqlConnection(sqlConnectionString))

    {

    using (SqlCommand comm = new SqlCommand(sprocName, conn))

    {

    try

    {

    comm.CommandType = CommandType.StoredProcedure;

    comm.Parameters.Add(new SqlParameter(paramName, paramDataType));

    comm.Parameters[paramName].Value = paramValue;

    comm.Connection.Open();

    comm.ExecuteNonQuery();

    }

    catch (Exception ex)

    {

    throw new Exception(errMessage, ex);

    }

    }//end of using block for SqlCommand

    }//end of using block for SqlConnection

     

     

    I believe this forum is NOT intended to get a complete solution written and given to you. You want to work on it by yourself and come & ask a specific problem/question you are having working on a solution.

    Thursday, March 27, 2008 11:51 PM
  •  little_birdie wrote:

    Hello,

    I am a SQL Programmer in need of a simple C# Console Application.

     

    Basically, I want a C#.NET code that will do the following:

     

    1.Query a sql table and return the results in the form of a dataset. The query is as simple as 'Select DNIS from Phone'

     

    2.Update a SQL table using the result of the previous query.

    The update statement is 'Update Redirect_Number Set Number = DNIS'

     

    Thank you.

     

     

     

     

     

    Now you need to write the actual program.

    Code Snippet

     

    private DataTable Populate(string sqlCommand)

    {

    DataTable table = new DataTable();

    SqlConnection sqlConnection = new SqlConnection(connectionString);

    sqlConnection.Open();

    SqlCommand command = new SqlCommand(sqlCommand, sqlConnection);

    SqlDataAdapter adapter = new SqlDataAdapter();

    adapter.SelectCommand = command;

    table.Locale = System.Globalization.CultureInfo.InvariantCulture;

    adapter.Fill(table);

    sqlConnection.Close();

    return table;

    }

     

     

    The variable connectionString is a connection string. 

    The variable sqlCommand is a SQL query. 

     

    Rudedog

    Friday, March 28, 2008 1:00 AM