0

hi frnnds,
iam raghuram,
i had got a problem .when iam inserting the values in database ,it will not inserted.
i had done the coding ,but it doesn't show any mistakes.
while inserting the data it will show error on
insert.executenonquery()
so i requested pls give me the coding of inserting data into database........here iam using technologies are asp.net with vb.net,sqlserver-2005..

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by nyagei
0

hi frnnds,
iam raghuram,
i had got a problem .when iam inserting the values in database ,it will not inserted.
i had done the coding ,but it doesn't show any mistakes.
while inserting the data it will show error on
insert.executenonquery()
so i requested pls give me the coding of inserting data into database........here iam using technologies are asp.net with vb.net,sqlserver-2005..

This is in C#, am sure you can convert it into VB.Net

string strInsert = "insert into myTable(field1, field2) values(?,?) ";
        openConnection();
        OleDbCommand myCommand = new OleDbCommand(strUpdate, cnConnection);

        myCommand.CommandType = CommandType.Text;

        myCommand.Parameters.Add(new OleDbParameter("@field1", OleDbType.VarChar));
        myCommand.Parameters["@field1"].Direction = ParameterDirection.Input;
        myCommand.Parameters["@field1"].Size = 150;
        myCommand.Parameters["@field1"].Value = "value 1";

myCommand.Parameters.Add(new OleDbParameter("@field2", OleDbType.VarChar));
        myCommand.Parameters["@field2"].Direction = ParameterDirection.Input;
        myCommand.Parameters["@field2"].Size = 150;
        myCommand.Parameters["@field2"].Value = "value 2";

try
        {
            intAdd = myCommand.ExecuteNonQuery();
        }
        catch (OleDbException ex)
        {
           //display error
        }
        finally
        {
            myCommand.Dispose();
            closeConnection();
        }

Edited by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.