blah blah blah is here! blah blah » Close

up0down
link

How do I set/get data from SQL2000 database using C#? I set up a table inside the database. The database is called "xDB" and the table I want to access is called "tbl_ES" with the column "ES" of type ntext.

last answered 2 years ago

1 answers

up0down
link

First, You should connect to DataBase:
private OleDbConnection ConBD;
//...//
private void Connect()
{
try
{
ConBD = new OleDbConnection("Provider=SQLOLEDB;Server=localhost;uid=sa;pwd=;database=xDB");
}
catch(Exception e){//Write a message}
}
private void getData()
{
OleDbDataReader dreader;
OleDbCommand CMD = new OleDbCommand("Select * from tbl_ES",ConBD);
CMD.CommandType = CommandType.Text;
CMD.CommandText = "Select * from tbl_ES";
ConBD.Open();
dreader = CMD.ExecuteReader();
while (dreader.Read())
{
data_1=dreader[0].ToString();dat_2=dreader[1].ToString();data_3=dreader[2].ToString();//...
}
dreader.Close();
ConBD.Close();
}
Ok, write it,
Good luck.

up0down
link

Thanks alot ncsharp! You wouldn't happen to know how to write to the same table?

up0down
link

If you need to do this quick and easy, I'd use a DataSet and DataAdapter, and let it write the code for you (at least initially). It'll create the SQL for you, if you choose. Check out DataAdapter on msdn. Basically, you tell it the Select statement (table, fields) and it figures the rest out.
HTH,

This post was imported from csharpfriends, if you have a similiar question please ask it again.

All previous members have been migrated, hope you enjoy the new platform!

Feedback