-
[RESOLVED] Ok Some Very Newbie Questions
Hi there...
I used to build VB apps like 4 years ago with VB 6.0 and using VBA with Access. I've since moved on to bigger and better things and I'm now a SQL Server Developer.
I've done a lot of cool things programming in SQL Server itself IE functions and stored procedures and using the Report Server to deploy our reports on our intranet.
However, I need to do some cooler things now. I need to be able to have my users update tables ... put in custom information in a form and send it back to the server to actually change values in tables and things.
I thought an easy way to do it would be to create a VB application. So, I had IT install the real version of Visual Studio 2005.
Here are my questions:
#1 Am I actually using VB.NET in Visual Studio 2005?
#2 I added a dataset to the windows application I started, and it put the connection information in as XML. Is that good? What can I do with this dataset?
#3 If I want to accomplish what I need to do ...should I be writing ADO to connect to the database? If so, do I use an ODBC type of connection or just standard ADO? I'm not entirely sure how to write a SQL Server 2005 connection string and then how I interact with it.
Sorry for the long post, but I've been out of the game for a long time and unfortunately, for me, programming is not like riding a bike... I do forget! I used to be able to just start writing VB but now I find myself at a loss.
The most I've gotten my application to do so far is display the contents of the table that I connected to. I have looked at the help files and tried to figure this stuff out...but I'm not sure if its tailored to the program that I'm using and what I specifically need to do.
Any help is appreciated.
-
Re: Ok Some Very Newbie Questions
Welcome to the forums. :wave:
Quote:
Originally Posted by Amythyst
#1 Am I actually using VB.NET in Visual Studio 2005?
Yes
Quote:
Originally Posted by Amythyst
#3 If I want to accomplish what I need to do ...should I be writing ADO to connect to the database? If so, do I use an ODBC type of connection or just standard ADO?
You should be using ADO.NET - there is a tutorial on using this in our Tutorial section.
-
Re: Ok Some Very Newbie Questions
Thanks... I actually read the tutorial and I'm still confused. I downloaded the word document he sent but its connecting to an access database and I'm still confused on the syntax for connecting to a sql server.
-
Re: Ok Some Very Newbie Questions
http://www.vbforums.com/showthread.php?t=469872
I think John did a pretty good job explaining in this post.
-
Re: Ok Some Very Newbie Questions
Quote:
Originally Posted by Amythyst
Thanks... I actually read the tutorial and I'm still confused. I downloaded the word document he sent but its connecting to an access database and I'm still confused on the syntax for connecting to a sql server.
Are you looking for what you would use as a connection string?
-
Re: Ok Some Very Newbie Questions
You'll find this series of articles very handy indeed:
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx
-
Re: Ok Some Very Newbie Questions
Quote:
Originally Posted by Hack
Are you looking for what you would use as a connection string?
Yes, I can't find the syntax for the connection string...every tutorial I look at just says "insert your connection string here"... but what if I dunno what it is ... lol.
-
Re: Ok Some Very Newbie Questions
Here is how I do it
vb.net Code:
Imports System.Data.SqlClient
Public myConnection As SqlConnection
Public Sub OpenDB()
myConnection = New SqlConnection("Integrated Security=SSPI;" _
& "Persist Security Info=False;Initial Catalog=xxxxxx; " _
& "Data Source=xxxxxxxxxx")
myConnection.Open()
End Sub
For connection string info, bookmark this site:
http://www.connectionstrings.com/
-
Re: Ok Some Very Newbie Questions
Thanks! That's helpful.
What does this mean:
Imports System.Data.SqlClient
Also, when I use your syntax... it doesn't recognize anything...
It keeps saying that the syntax is wrong for Imports, SqlConnection, SqlCommand...
What am I doing wrong?
-
Re: Ok Some Very Newbie Questions
It is a reference to a class that contains all of the stuff that is required to connect to an SQL Server database.
What you "Import" will differ from database to database. For instance, that Import would not work if I were trying to connect to an Oracle database.
I actually didn't have to use that. I could have done this
vb.net Code:
Public Sub OpenDB()
myConnection = New System.Data.SqlClient.SqlConnection("Integrated Security=SSPI;" _
& "Persist Security Info=False;Initial Catalog=pcds; " _
& "Data Source=buddevdb")
myConnection.Open()
End Sub
The results would have been the same.
-
Re: Ok Some Very Newbie Questions
Hmm... I must be missing something... I made an edit to my previous post... I'm getting a lot of syntax errors as it doesn't recognize these sql statements.
-
Re: Ok Some Very Newbie Questions
Post everything on your form.
-
Re: Ok Some Very Newbie Questions
I haven't even put any of my info in it yet but even pasting it in, it doesn't recognize these statements (I copied this from the tutorial page and I pasted in your connection string stuff):
Imports System.Data.SqlClient
Dim connection As New SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=BAPROD;Data Source=Portales")
Dim command As New SqlCommand("INSERT INTO StockItem (Name, Quantity, Unit) VALUES (@Name, @Quantity, @Unit)", connection)
command.Parameters.AddWithValue("@Name", someName)
command.Parameters.AddWithValue("@Quantity", someQuantity)
command.Parameters.AddWithValue("@Unit", someUnit)
connection.Open(command.ExecuteNonQuery())
connection.Close()
The imports is underlined...the sqlconnection is underlined the command is underlined....sqlcommand is underlined...
-
Re: Ok Some Very Newbie Questions
Where is the Imports Statement? It need to be above any thing else in the Code section of the form (above the class declare).
-
Re: Ok Some Very Newbie Questions
First of all, make sure you use Option Strick On
Second, the Imports statement MUST go ABOVE Public Class YourFormName
If it is BELOW that, it will cause an error.
-
Re: Ok Some Very Newbie Questions
Also, is your code pasted into an event? Did you check out the link in post #4?
-
Re: Ok Some Very Newbie Questions
You need to add a reference in the project for System.Data.SQLClient.
-
Re: Ok Some Very Newbie Questions
Ok, I think I fixed it... duh. :)
One more question... I have the following code that works! Cause I checked the table in SQL Server.
Dim txtTest As Double
txtTest = Me.TextBox1.Text
Dim connection As New SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=BAPROD;Data Source=Portales")
Dim command As New SqlCommand("UPDATE ThirteenWeek SET TradeReceivables = " & txtTest & " ", connection)
connection.Open()
command.ExecuteNonQuery()
connection.Close()
Me.DataGridView1.Refresh()
My question is with the DataGridView that I put on the form... it shows all the records from the table on the form... I tried to refresh it but it didn't work. Am I doing it wrong?
-
Re: Ok Some Very Newbie Questions
Well, it is getting the data from your database right?
What are you doing right before you are trying to refresh it?
(You are closing the connection to the database)
-
Re: Ok Some Very Newbie Questions
Yes, the datagrid is not using the database connection in this sub though. I had to add a datasource to the project to get the datagrid to work. Its using a connection string in the app.config
So, if I refresh it...shouldn't it refresh?
-
Re: Ok Some Very Newbie Questions
It will refresh by grabing a new copy of what is in your table, so if it can get to your table, it should refresh. If it can't, then it won't refresh.
-
Re: Ok Some Very Newbie Questions
Hmm well that doesn't help... it doesn't appear to do anything... the code doesn't error but it doesnt do anything. If you close it and reopen it, the updated values are there.
-
Re: Ok Some Very Newbie Questions
Ah ha! I fixed it myself...(go me) I had to add this line before the refresh:
Me.ThirteenWeekTableAdapter.Fill(Me.BAPRODDataSet.ThirteenWeek)
-
Re: Ok Some Very Newbie Questions
One more question... and I did do a search first before I'm asking and I didn't find it...
I want to create a combo box that contains a listing of fields from a table... how would I go about doing that?
-
Re: Ok Some Very Newbie Questions
Look into Information_Shema views in SQL Server.