Lecture 6 2nd Course C#
Lecture 6 2nd Course C#
1
C# Objects (controls)
1-Command Update
2-Call all data from table to objects
3-Display the selected row from dataGV to textbox
Description
private void button2_Click(object sender, EventArgs e)
{ try {
//This is my connection string i have assigned the database file address path
string MyConnection2 = "datasource=localhost;port=3307;username=root;password=root";
//This is my update query in which i am taking input from the user through windows forms and
update the record.
string Query = "update student.studentinfo set idStudentInfo='" + this.IdTextBox.Text + "',Name='"
+ this.NameTextBox.Text + "',Father_Name='" + this.FnameTextBox.Text + "',Age='" +
this.AgeTextBox.Text + "',Semester='" + this.SemesterTextBox.Text + "' where idStudentInfo='" +
this.IdTextBox.Text + "';";
//This is MySqlConnection here i have created the object and pass my connection string.
MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
MySqlDataReader MyReader2;
MyConn2.Open();
MyReader2 = MyCommand2.ExecuteReader();
MessageBox.Show("Data Updated");
while (MyReader2.Read())
{ }
MyConn2.Close();//Connection closed here
}
catch (Exception ex)
{
MessageBox.Show(ex.Message); }
2
Example 1 Command Update
3
Example 2 Command Update
4
Example 3 Display selected row from datagridview to textbox
5
- Example 4 Display selected row from datagridview to textbox using ID
# How to search for object information using textbox-based ID and display the information over
their textbox as shown in windows.