Wednesday, 14 March 2012

DataGridView in Windows Forms Part - 1

Populating a DataGridView

In this short snippet, we will populate a DataGridView using the LoadData() method. This method uses the SqlDataAdapter to populate a DataSet. The table ‘Orders’ in the DataSet is then bound to the BindingSource component which gives us the flexibility to choose/modify the data location.
C#
public
{
InitializeComponent();

txtDate.Text = dt.ToString(

 //  Here You can convert  date into following format
 false;//@id,@name,@item_list,@sub_item,@weight,@mixing,@sys_date,@perc,@labour_chg,@fine_gold
{




{

insertID =
txtID.Text = insertID.ToString();
cmd.Parameters.AddWithValue(
}
cmd.Parameters.AddWithValue(
cmd.Parameters.AddWithValue(
cmd.Parameters.AddWithValue(
cmd.Parameters.AddWithValue(
private void button1_Click(object sender, EventArgs e)SqlConnection con = new SqlConnection("Data Source=source_name;User ID=Nihar;Password=******");string insertsql = "INSERT INTO [TestApp].[dbo].[gold_test1]([id],[name],[item_list],[sub_item],[weight])VALUES (@id,@name,@item_list,@sub_item,@weight)";SqlCommand cmd = new SqlCommand(insertsql, con);if (txtID.Text != string.Empty)string insertID;"select id+1 from gold_test1 where id=(select max(id) from gold_test1)";"@id", txtID.Text);"@name",txtName.Text);"@item_list",txtItem1.Text);"@sub_item",txtSubItem.Text);"@weight", txtWeight.Text);con.Open();
cmd.ExecuteNonQuery();
con.Close();
}

txtDate.Enabled =
}
Form1()DateTime dt = new DateTime();"dd/MM/yyyy"); 

No comments:

Post a Comment