Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL in VB . NET

Status
Not open for further replies.

skarosi

Programmer
Jan 25, 2004
140
GR
Hi all,
I am just moving to the database programming of VB, even though i have used some SQL in the past, but on its own, with out any other programming language.
any way, i want to ask for your help,
I want to create a VB application, that handles some tables written in SQL server. do you have any ideas? i am totaly lost here.
any pointer would be wellcome.
Thanks
 
What exactly are you doing? and what kind of SQL would you like to know. I use stored procedures in SQL Server and then i access then from VB.Net. I can post some functions as to how i access my SQL server in code and perform other functions. What are you going to do with the data in the tables? if your just going to view data then i can point you in that direction but if your going to need to update,insert, and delete data then there is another way to do things. then finally what controls are you going to use on your form to display the data, like textboxes, datagrids, lists, and etc.

Sincerely,
Fritts
 
i just want to view the data using some sql queries presented in a nice way, thats all.
nothing too fancy
 
The best thing to do is

1. create a stored procudure to return the result set. 2. Create a SQLConnection, connect to the DB.
3. Create a SQLdataadapter using the connection and refernce the stored procedure.
4. Create and fill a dataset from the SQLDataAdapter.
5. Bind a datagrid's datasource to the default table in the Dataset.
 
ok, i will try this, even though i am not sure how i am suppose to do all these, but i guess i can look on a book or something.
thanks man
 
Here is some code for you, just use a datagrid and this code

Private Sub GetData()
'Put this two dims in your declaration section you don't want declare this every time you hit this function
dim daTrial as SqlDataAdapter
dim dsTrial as new Dataset

daTrial = New SqlDataAdapter


'Dim daTrial As New SqlDataAdapter
daTrial.SelectCommand = New SqlCommand


Try

With daTrial.SelectCommand
.Connection = conMain
.CommandType = CommandType.StoredProcedure
.CommandText = "use name of store procedure here"
.Parameters.Clear()
'parameter of your stored procedure
.Parameters.Add("@EmpID", SqlDbType.VarChar, 3, "EmployeeID").Value = EmpID
.Parameters.Add("@WorkDate", SqlDbType.SmallDateTime, 4, "WorkDate").Value = IDate
End With

'Bind to a dataset
daTrial.Fill(dsTrial, "Trial")
'then bind to your datagrid like this by binding to your dataset
datagrid.DataSource = dsTrial.Tables("Trial")

i hope this works out for you just let me know how this goes and you can also use a datareader instead of a dataadapter.
Once you get this part working i can help you with the datagrid and locking down the columns so a user can't mess things up.
 
Thanks for the help, I will try this.
even though i have a problem using the stored procedure thing. i have looked it on a book, but it has it way too complicated.
anyway, i will try this
thanks
by the way, does this code goes to the datagrid procedure?
 
This is just a public function, i create a function so i can load the data for different event, you really don't want to get into messing around with the gird procedures yet. This code will load any data in your dataset as long as you bind the two together. You can use this code fire an event where ever you want like a command button click event. i use it from a drop down combo box click event which has list of variables to chooose from.
Please let me know how this goes, i can help you with stored procedures if you would like i just need to know what your tables are and in plane english what you would like.

Sincerely,
Fritts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top