QUOTE(programmer2u @ 3 Jul, 2009 - 12:57 PM)

[b]hi PLEASE SOMEONE TELL ME WHY THIS CODE NOT WORKING
AS THERE WERE NO ERRORS , BUT WHEN I ADD NEW RECORDS IT NOT INSERT IN DATABASE
CODE
void Button6Click(object sender, EventArgs e)
{
System.Data.OleDb.OleDbDataAdapter da;
string connect="Provider=Microsoft.jet.oledb.4.0;data source=.\\db1.mdb";
toolStripProgressBar1.Value=25;
OleDbConnection con = new OleDbConnection(connect);
con.Open();
DataSet ds1;
ds1=new DataSet();
//ds1.Tables.Add("r");
toolStripProgressBar1.Value=25;
string sql="select * from red";
da= new System.Data.OleDb.OleDbDataAdapter(sql,con);
System.Data.OleDb.OleDbCommandBuilder cb;
cb = new System.Data.OleDb.OleDbCommandBuilder( da );
da.Fill(ds1,"red");
int MaxRows = 0;
int inc = 0;
MaxRows = ds1.Tables["red"].Rows.Count;
//To add a record to the Dataset, you need to create a new Row
DataRow dr=ds1.Tables["red"].NewRow();
MaxRows = MaxRows + 1;
inc = MaxRows - 1;
MessageBox.Show(textBox2.Text);
//But the Row will not have any data.
//To add data to the row, the format is this:
dr[1]=textBox2.Text.ToString();
dr[2]=textBox3.Text.ToString();
toolStripProgressBar1.Value=75;
//Finally, you issue the Add command:
ds1.Tables["red"].Rows.Add(dr);
ds1.AcceptChanges();
//The only thing you need to do is tell it which Dataset holds
//all the records, and its name:
//da.Update( ds1, "Workers" );
da.Update(ds1,"red");
toolStripProgressBar1.Value=100;
con.Close();
}
}
}
Mod Edit: Please use code tags when posting your code. Code tags are used like so =>

Thanks,
PsychoCoder

This one should work for you
And also, think you need some ADO.NET basic
Take a look at MSDN library about Insert, Update
and Delete commands
From other side using of Try...Catch statment is
would be a good practic for you
Change column names to your suit
CODE
private void button6_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
try
{
System.Data.OleDb.OleDbDataAdapter da;
string connect = "Provider=Microsoft.jet.oledb.4.0;data source=.\\db1.mdb";
//toolStripProgressBar1.Value = 25;
con.ConnectionString = connect;
this.Cursor = Cursors.WaitCursor;
con.Open();
DataSet ds1;
ds1 = new DataSet();
//ds1.Tables.Add("r");
//toolStripProgressBar1.Value = 25;
string sql = "select * from red";
da = new System.Data.OleDb.OleDbDataAdapter(sql, con);
System.Data.OleDb.OleDbCommandBuilder cb;
cb = new System.Data.OleDb.OleDbCommandBuilder(da);
da.Fill(ds1, "red");
//int MaxRows = 0;
//int inc = 0;
//MaxRows = ds1.Tables["red"].Rows.Count;
//To add a record to the Dataset, you need to create a new Row
DataRow dr = ds1.Tables["red"].NewRow();
//MaxRows = MaxRows + 1;
//inc = MaxRows - 1;
//MessageBox.Show(textBox2.Text);
//But the Row will not have any data.
//To add data to the row, the format is this:
dr["Column1"] = textBox2.Text.ToString();
dr["Column2"] = textBox3.Text.ToString();
//toolStripProgressBar1.Value = 75;
//Finally, you issue the Add command:
ds1.Tables["red"].Rows.Add(dr);
//ds1.AcceptChanges();
// create insert sql string
sql = string.Format("insert into red " +
"(Column1, Column2) values " +
"('{0}','{1}')", textBox2.Text, textBox3.Text);
//create insert command, set properties
da.InsertCommand = new OleDbCommand(sql);
da.InsertCommand.Connection = con;
//The only thing you need to do is tell it which Dataset holds
//all the records, and its name:
//da.Update( ds1, "Workers" );
da.Update(ds1.Tables["red"]);
//toolStripProgressBar1.Value = 100;
}
catch (OleDbException oex)
{
MessageBox.Show(oex.Message + "\n" + oex.StackTrace);
}
finally
{
con.Close();
}
this.Cursor = Cursors.Default;
}