Am hoping you can help out a beginner here. I am using VS 2008 express, with C#.net.
I have created a DB via the IDE and it is connected to a set of field on my form. I want to be able to update the data within the database, and selected to update the form programatically...ie based on events within the program.
I have a beginners book that shows some very basic DB stuff, but nothing programatically...ie using update
Sam HobbsPosted Dec 9, 2009, 11:58 AM
Note that there are things called TableAdapters. They are very useful and they get created for you by the IDE. Unfortunately they are not documented very well, but other wise the IDE will do very much for you. You need to get more books; the thing you need to look for is one that describes TableAdapters as well as many other database things, including business layers and business objects.
Kirtan PatelPosted Dec 8, 2009, 9:51 PM
Creating Separate Class for Performing DB operation is called BLL (Business Logic Layer) thats good thing if you do it :)
but its not necessary if you have very small application.
if my answer helps you then check "do you like this answer" check box :)
and for updating database you can do code like below
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Connection String Here");
con.Open();
SqlCommand comm = new SqlCommand("update tablename set field1=value where id=1", con);
comm.ExecuteNonQuery();
con.Close();
}
Jeff FarrPosted Dec 8, 2009, 5:27 PM
Create your command with variables
tSql = "SELECT statement FROM
create your connections, command and reader then do an execute:
sqlConn.Open();
reader.Close();
mc = new SqlCommand(tSql, sqlConn);
reader = mc.ExecuteReader();
There is another option to use LINQ, but I perfer to use the good old fashioned way.
GaryPosted Jul 17, 2009, 3:31 AM
Sorry guys, but I am really interested to hear your opinions on this.