hi,
i have Ms Access database having three fields
ID
username
password
and i want to make form that update them, my table name is studentLoginData

MessageBox.Show("the password is matched");
                String conString = "Provider=Microsoft.Jet.OLEDB.4.0;"
                 + "Data Source=C:\\Documents and Settings\\Wasif\\My Documents\\studentLogin.mdb";
                SqlConnection objConn = new SqlConnection(conString);
                try
                {
                    objConn.Open();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                SqlDataAdapter daAuthors = new SqlDataAdapter("Select * From StudentLoginData", objConn);
                DataSet dsPubs = new DataSet("Pubs");
                daAuthors.FillSchema(dsPubs, SchemaType.Source, "studentData");
                daAuthors.Fill(dsPubs, "studentData");
                DataTable tblAuthors;
                tblAuthors = dsPubs.Tables["studentData"];
               
                try
                {
                    DataRow drCurrent;
                    drCurrent = tblAuthors.NewRow();
                    drCurrent["ID"] = txt_id.Text;
                    drCurrent["username"] = txt_username.Text;
                    drCurrent["password"] = txt_password.Text;
                    drCurrent = tblAuthors.Rows.Find(txt_id.Text);
                    drCurrent.BeginEdit();
                    drCurrent["ID"] = txt_id.Text + drCurrent["ID"].ToString().Substring(0);
                    drCurrent["username"] = txt_username.Text + drCurrent["username"].ToString().Substring(1);
                    drCurrent["password"] = txt_password.Text + drCurrent["password"].ToString().Substring(2);
                    drCurrent.EndEdit();
                    MessageBox.Show("record has been updates");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

there is my code

u can't update the ID field cause it's an automatically update field along with primary key

beside that

first you need to add a new row
then add data to it
then add that row with dataset
then use CommandBuilder to Update the DataBase

System.Data.OleDb.OleDbCommandBuidler _comd;
_comd = new System.Data.OleDb.OleDbCommandBuidler(dataAdapter); //this useful work with .UpdateMethod of DataAdapter

//add data likewise you have already done

_dataSet.Tables["tablessName"].Rows.Add(_rowsName);
_dataAdapter.Update(Dataset,"itsTablesName");
_connection.Close();

thanks for your replay but i m not able to solve my problem can you write down full code ..
i have 3 fields
ID
username
password
and from txtboxes i want to update them
thanks ..

Write down the SQL equivalent of what you want to do.

That will put things in perspective for you.

commented: . +0
SqlConnectin _con;
SqlDataAdapter _adp;
SqlCommand _com;
SqlCommandBuilder _comB;
DataSet _set;

public form1 //this is the constructor (if u don't know what's that mean then u //should probably learn C# from the beginning) 
{

string _comStr = "SELECT * From table'sName"
_con  = new SqlConnectin();
_con.ConnectionString ="Provider=Microsoft.Jet.OLEDB.4.0;"+
"Data Source=C:\\Documents and Settings\\Wasif\\My Documents\\studentLogin.mdb";
_com = new SqlCommand(_comStr,_con);
_adp = new SqlDataAdapter() ;
_set =  new DataSet();
_adp.SelectCommand = _com;

}

public submit()
{
_con.Open();
_adp.Fill(_set,"dataSetTableName");
_con.Close();


DataRow[] _arrayRow = _set.Tables["dataSetTableName"].Select("userName='" +txtUserName.Text + "'");

if(_arrayRow.Length >0)
{
DataRow _single = _arrayRow[0]; //get only one username cause obviously there shouldn't be two user names in same name

//update (u can't update the ID field it's an automatically field)
DataRow["userName"] = txtUserName.Text;
DataRow["Password"] = txtPassword.Text;

_comB = new SqlCommandBuilder(SqlDataAdapter);
_adp.Update(_set,"dataSetTableName");
_con.Close();

}

}

if I have any mistake then tell me .! I would correct them cause I typed too fast./

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.