Hello,
I am working on an application which is connected to a sql server 2008 database. I used the visual studio tool to connect to the database which allows me to show data in a datagrid. But now I want to execute other queries (add/ modify....) but I don't know how to do it. I mean I've already used sql so writing queries is not a problem but how to do it with visual studio....I've already googled on this topic and tried different solutions but it just isn't working. Can someone please give me an example of these queries? I'm using visual studio 2010.
I'd really appreciate some help here.
Thanks in advance.
Anila
Loading
AnilaPosted Jun 9, 2011, 10:26 AM
Sam HobbsPosted Jun 8, 2011, 9:09 PM
Dorababu MekaPosted Jun 8, 2011, 8:35 AM
http://www.visualbuilder.com/showCode.php?id=81373&scd_id=2978
AnilaPosted Jun 8, 2011, 8:20 AM
As you can see in my code that I haven't used SqlConnection directly in my code(I followed an example on msdn walkthroughs) can you please give me an example which goes with my model.
AnilaPosted Jun 8, 2011, 8:15 AM
Dorababu MekaPosted Jun 8, 2011, 8:08 AM
AnilaPosted Jun 8, 2011, 8:01 AM
So what I want is an application connected to sql server, this application allows user to view information from the database on a grid and to modify the data. What I've done so far is that I've created a function that loads the information in a datagrid using following code:
TestEntities dataEntities = new TestEntities();
private void Form1_Load(object sender, EventArgs e)
{
ObjectQuery
var query = from worker in products
where worker.First_Name == "A"
select new { worker.First_Name, worker.Last_Name, worker.Telephone_Number, worker.Postal_Code, worker.Joining_Date };
dataGrid1.DataSource = query.ToList();
}
Now I want to be able to modify an existing entry or add a new one.
Shirsendu NandiPosted Jun 8, 2011, 7:56 AM
Shirsendu NandiPosted Jun 8, 2011, 7:55 AM
con.open();
String query="select * from dbo.[yourtablename]"
SqlCommand cmd=new SqlCommand(query,con);
cmd.executenonquery();
con.close();
///
See here in the String query you can write your other query and just pass it through the command.
Dorababu MekaPosted Jun 8, 2011, 7:51 AM