Help with updating & modify data

  • Thread starter Thread starter MikeY
  • Start date Start date
M

MikeY

Hi everyone,

I have posted earlier this week, but I'm still scratching my head trying to
figure out how to change/modify my data back to my db.

Using C# Windows forms. I am trying to learn how to modify existing data
with in my DB/MSDE. In general, I have textbox's filled with existing data
from my "Employee" table. I have amongst other buttons, an "Update" button.
Where, when viewing, if I want to change ie the persons name, anyother
field, or all fields I want to press the update button. However I am getting
lost. My code is below with the 3 fields I want to update. Mapping is in the
correct order. Hopefully someone can help by providing correct code or a
link example.

private void btnEmpModify_Click(object sender, System.EventArgs e)
{
DataTable thisTable = dsModifyRecord.Tables["Employee"];
//THIS IS WHERE I'M GETTING LOST
thisTable.Rows[??????????????];

thisRow["EmpFName"] = txtBoxEmpFName.Text;
thisRow["EmpLName"] = txtBoxLNName.Text;
thisRow["EmpTitle"] = txtBoxEmpTitle.Text;


//& GETTING LOST HERE
dsModifyRecord.Tables["EMPLOYEE"]??????????????
sqlDataAdapter1.Update(dsModifyRecord, "Employee");
}

Thank you all in advance

MikeY
 
Hi Mike,

DataTable can contain many rows, you have to select the one that you want to
update.
When you read your data froom the database, it returns several records, one
record, or no records.
How do you fill the text box with your data? Which record from your
DataTable are you using?
(e-mail address removed)
 
Hi Codewriter,

I fill my textbox's with a sql datareader. What I do is a search for a
particular field. If the field is found, I output the info to textbox's but
I wanted to have the ability to mdofiy, ie persons first name if needed. A
sample of my code is as follows for the datareader/search:


try
{
string userinput = txtBoxEmpSearch.Text;
sqlConnection1.Open();
string select = "SELECT * FROM Employee WHERE (EmpID = '" + userinput +
"')";
SqlCommand cmd = new SqlCommand(select, sqlConnection1);
SqlDataReader myReader = cmd.ExecuteReader();
while(myReader.Read())
{
returnedValue = myReader.GetString(1);
userIDOutPut = Convert.ToString(myReader.GetInt32(0));
userFNameOutPut = myReader.GetString(1);
userLNameOutPut = myReader.GetString(2);
userTitleOutPut = myReader.GetString(3);
txtBoxtmp.Text = myReader.GetString(3); //Temp for Deletion
}

Thanks for help.


codewriter said:
Hi Mike,

DataTable can contain many rows, you have to select the one that you want to
update.
When you read your data froom the database, it returns several records, one
record, or no records.
How do you fill the text box with your data? Which record from your
DataTable are you using?
(e-mail address removed)

MikeY said:
Hi everyone,

I have posted earlier this week, but I'm still scratching my head trying to
figure out how to change/modify my data back to my db.

Using C# Windows forms. I am trying to learn how to modify existing data
with in my DB/MSDE. In general, I have textbox's filled with existing data
from my "Employee" table. I have amongst other buttons, an "Update" button.
Where, when viewing, if I want to change ie the persons name, anyother
field, or all fields I want to press the update button. However I am getting
lost. My code is below with the 3 fields I want to update. Mapping is in the
correct order. Hopefully someone can help by providing correct code or a
link example.

private void btnEmpModify_Click(object sender, System.EventArgs e)
{
DataTable thisTable = dsModifyRecord.Tables["Employee"];
//THIS IS WHERE I'M GETTING LOST
thisTable.Rows[??????????????];

thisRow["EmpFName"] = txtBoxEmpFName.Text;
thisRow["EmpLName"] = txtBoxLNName.Text;
thisRow["EmpTitle"] = txtBoxEmpTitle.Text;


//& GETTING LOST HERE
dsModifyRecord.Tables["EMPLOYEE"]??????????????
sqlDataAdapter1.Update(dsModifyRecord, "Employee");
}

Thank you all in advance

MikeY
 
Back
Top