Windows Form Application With Data Binding
Windows Form Application With Data Binding
public MyForm() {
}
}}
public class MyForm : Form
• Update query:
SqlCommand updateCommand = new SqlCommand("UPDATE [Login] SET
Name=@n WHERE Percentage=@r", con);
updateCommand.Parameters.Add("@n", SqlDbType.VarChar, 255,"Name").Value =
textBox1.Text;
updateCommand.Parameters.Add("@r", SqlDbTypeSqlDbType.Int, 0,
"Percentage").Value = int.Parse(textBox3.Text);
int queryResult = updateCommand.ExecuteNonQuery();
• Select query to display in MessageBox
SqlCommand select = new SqlCommand("SELECT Percentage FROM Login where
Name=@n", con);
select.Parameters.Add("@n", SqlDbType.NVarChar, 255, "Name").Value =
textBox1.Text;
SqlDataReader aReader = select.ExecuteReader();
while (aReader.Read())
{
int n = aReader.GetInt32(0);
MessageBox.Show("Percentage " + n);
}
aReader.Close();
• Select query to display in DataGridView
SqlDataAdapter adp = new SqlDataAdapter("select * from Login", con);
DataSet ds = new DataSet();
adp.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
MDI in Windows Form
• The Multiple-Document Interface (MDI) is a specification that defines a user
interface for applications that enable the user to work with more than one
document at the same time under one parent form (window).
Form2 f = new Form2();
f.Show();