0

Hi
I have a database with two tables
1. iSet(which contains data)
2.Table1(which is empty)

I have a program that can read from iSet.
It uses OleDB
Its working properly

The problem is that i don't know a thing about writing to a database.

The table Table1 has two fields
iAddress(of type number)
Instruction(of type string)
ID(Autonumber)

How to write values to Table1?

Thanks in advance

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by vivek4020
1

Try this.

static void Main(string[] args)
        {
            OleDbConnection connection = new OleDbConnection("your_connection_string_here");

            string sql = "Insert Into Table1 (iAddress, Instruction) values (@iAddress, @instruction)";
            
            OleDbParameter addressParam = new OleDbParameter("@iAddress", OleDbType.Integer);
            addressParam.Value = 1;

            OleDbParameter instructionParam = new OleDbParameter("@instruction", OleDbType.VarChar);
            instructionParam.Value = "Test";

            OleDbCommand command = new OleDbCommand(sql, connection);
            command.Parameters.Add(addressParam);
            command.Parameters.Add(instructionParam);

            connection.Open();
            command.ExecuteNonQuery();
            command.Dispose();
            connection.Close();
            connection.Dispose();
        }

Edited by apegram: n/a

Votes + Comments
Thanks. It Worked
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.