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.");
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE