Totally Lost and frustrated: visual studio c# 2005 sql database interaction

  • Thread starter Thread starter garyusenet
  • Start date Start date
G

garyusenet

I have created a new project. and within this project as per the
tutorial created an sql database.

i have made a query which returns the result i need.

1. I cant SAVE THE QUERY? where on earth is the option to save a query?

2. How do i run an sql query from within c# ? i have a command button i
want to enter code for the command button that will run an sql query...
how do i do it?

thanks, im so frustrated with vs at the moment, the help doesn't even
work on my machine but it just says nothing can be found...

help please./

Gary.
 
Gary,

What do you mean you want to save the query? If you are using the
designer in VS.NET 2005, it stores your query in the designer-generated
code.

You can also create a stored procedure, and call that, and your query
will be in the database.

Hope this helps.
 
thanks for your reply please help some more
i can see four windows
1 - picture of table
2 - grid with columns in
3 - sql code
4 - returned result

i put my sql code in the 3rd window, and vs studio put some spaces in
and put split it up over a couple of lines, when i run it the result
appears in window 4.

I want to run this when a button on my form is pressed. I can't find
any designer-generated code you mention? how do i run this query from
within my c# code, attached to my command button on my form.

thank you

gary
 
Gary,

You should have a file in your C# project which represents the data set
that is the result of that query. In that designer file, you should see the
data adapters which are configured to run your query.
 
to elaborate a bit ...

my form consists some text boxes that i dragged from the 'data sources'
window.

when i press my command button i want to run the query so that only the
returned record appears on this form, and not all of the records in the
database.

also the query i run returns the name of a field, i would like to store
this in a variable called result$ when the query is run.

thanks

gary.
 
I have foudn a file called: betadataset.designer.cs

the table i'm using is called beta, so i think this might be the file
you reference.
I can double click this file and code is displayed.

I tried to copy all of this and paste it to the code that appears when
i double click on the button on my form, but that seems to have made
things worse, and now my form doesn't display properly.

I don't seem any closer to achieving what I need to achieve.
I have a form. This form displays records from my table. I have dragged
and dropped the text boxes to display the records onto the form, from
the data source window. When i run my app the records are displayed
fine.
All i want to do is add a button, that runs an sql query so that only
the records that match the query are displayed!!!??!

please how do i do this?
 
Gary,

There is no reason to cut and paste this. Those classes are available
to you, you just have to make sure that you have the right namespace and
type name. You should note that some of the table designer classes are
actually nested classes (although I think it is the tables themselves, and
the table adapters, I forget).

All you have to do is get the data adapter with your query, and then run
it. The class is in there somewhere. Look for something with
"TableAdapter" in it's name.
 
Back
Top