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

Dorababu MekaRank #457 · 5.5K reputationPosted Jun 8, 2011, 3:51 AM EDT
Shirsendu NandiRank #246 · 10.2K reputationPosted Jun 8, 2011, 3:55 AM EDT
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.
Shirsendu NandiRank #246 · 10.2K reputationPosted Jun 8, 2011, 3:56 AM EDT
Anila14 reputationPosted Jun 8, 2011, 4:01 AM EDT
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.
Dorababu MekaRank #457 · 5.5K reputationPosted Jun 8, 2011, 4:08 AM EDT
Anila14 reputationPosted Jun 8, 2011, 4:15 AM EDT
Anila14 reputationPosted Jun 8, 2011, 4:20 AM EDT
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.
Dorababu MekaRank #457 · 5.5K reputationPosted Jun 8, 2011, 4:35 AM EDT
http://www.visualbuilder.com/showCode.php?id=81373&scd_id=2978
Sam HobbsRank #107 · 20.5K reputationPosted Jun 8, 2011, 5:09 PM EDT
Anila14 reputationPosted Jun 9, 2011, 6:26 AM EDT