using (var db = new Model1())
{
//do a select
var query = from b in db.Customers
orderby b.CustID
select b;
// //Console.WriteLine("All blogs in the database:");
foreach (var item in query)
{
Console.WriteLine(item.CustID);
}
}
using (var db = new Model1())
{
// do the insert
}
using (var db = new Model1())
{
// do the update
}
using (var db = new Model1())
{
// do the delete
}
private void btnInsert_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
string constring = @"Data Source=.\SQL2008R2;Initial Catalog=AjaxSamples;Integrated Security=true";
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO Customers VALUES(@CustomerId, @Name, @Country)", con))
{
cmd.Parameters.AddWithValue("@CustomerId", row.Cells["Id"].Value);
cmd.Parameters.AddWithValue("@Name", row.Cells["Name"].Value);
cmd.Parameters.AddWithValue("@Country", row.Cells["Country"].Value);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
MessageBox.Show("Records inserted.");
}
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.