Hi, I've recently gotten started putting together an ASP.NET C# Web Application using Visual Studio .NET.
I've run into a problem with modifying my database through a form with a whole bunch of TextBox's. I have another identical form where I add new database records to the database by having the user enter text into the fields and hitting the "add new" button - this works fine.
My problem is in my update form. I retrieve the database records and put them into the corresponding textBox's. The user can then modify these text-box's and click the "modify" Button. The problem is, these changes the user makes to the textBox's don't seem to be taken into account when I update the database - it just uses the same values that were in the textBox's before the user modified them.
Here's the page_load function:
Code:
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
sqlDataAdapter1.Fill(dataSet1);
DropDownList1.DataSource = dataSet1;
DropDownList1.DataTextField = "patient_LastName";
DropDownList1.DataValueField = "patient_ID";
DropDownList1.DataBind();
}
sqlSelectCommand2.Parameters["@DropDownListID"].Value = DropDownList1.SelectedItem.Value;
sqlDataAdapter2.Fill(dataSet2);
txtFirstName.Text = (string) dataSet2.Tables["Patient"].Rows[0]["patient_FirstName"];
txtLastName.Text = (string) dataSet2.Tables["Patient"].Rows[0]["patient_LastName"];
txtMiddleInitial.Text = (string) dataSet2.Tables["Patient"].Rows[0]["patient_MiddleInitial"];
.....etc etc....
And here is the button click function:
Code:
private void Button1_Click(object sender, System.EventArgs e)
sqlSelectCommand4.Parameters["@patient_ID"].Value = DropDownList1.SelectedItem.Value;
sqlSelectCommand4.Parameters["@patient_FirstName"].Value = txtFirstName.Text;
sqlSelectCommand4.Parameters["@patient_LastName"].Value = txtLastName.Text;
..... etc etc .....
One thing I should mention - if I put txtFirstName.Text = "blah blah blah" at the top of that click button function, it inserts the "blah blah blah" string into the database. How do I get it to retrieve the text that the user types into the TextBox's?