|
-
Nov 25th, 2013, 01:01 PM
#1
Thread Starter
Junior Member
VB and SQL
Okay, I've got some other college work I might need some help with. I have a major project coming up in class next Wednesday that has to do with me creating a Windows Form-based application that connects to a database through SQL to allow for a user to connect using a login and password, also stored on a table within the database, and can allow for said user to edit, update, and change entries on another table.
Reason I'm asking for help is for one of four main things: For starters, when I installed SQL, after installing Visual Studio, I'm getting a connection issue when trying to add a data connection in the Server Explorer. Can anyone help me understand what exactly I'm doing wrong?
Second, once I have the tables created, the Windows forms must display said table and allow for editing. Is there anything I should know about allowing a user to do so?
Third, I do understand that, to get the form's variables and such to be recognized by SQL, a @ is needed before each variable entry in the SQL coding, if that makes any sense. This in mind, how do I get the user's input from another form I've made for the user to input their user name and password to the main form to be used in SQL? I've got an idea behind that, but I figured I'd ask.
Lastly, there is a requirement to allow for a user to switch tables within the database, however the project doesn't mention if it's required to keep it in the same form. Assuming it is required, how would I do that?
-
Nov 25th, 2013, 01:16 PM
#2
Re: VB and SQL
Here's a good place to start. http://msdn.microsoft.com/en-US/vstu...#formsoverdata
There's lots of information in this forum on how to transfer values between forms, just do a search.
-
Nov 25th, 2013, 01:18 PM
#3
Re: VB and SQL
 Originally Posted by NFSRacer
Reason I'm asking for help is for one of four main things: For starters, when I installed SQL, after installing Visual Studio, I'm getting a connection issue when trying to add a data connection in the Server Explorer. Can anyone help me understand what exactly I'm doing wrong?
We'd have to know what you're doing and what happens when you do it to know what you're doing wrong.
 Originally Posted by NFSRacer
Second, once I have the tables created, the Windows forms must display said table and allow for editing. Is there anything I should know about allowing a user to do so?
If you want to display a table of data then you'll probably want to use a DataGridView control. You can bind a populated DataTable to the grid by setting the control's DataSource property. Ideally you would bind the DataTable to a BindingSource and bind that to the grid.
 Originally Posted by NFSRacer
Third, I do understand that, to get the form's variables and such to be recognized by SQL, a @ is needed before each variable entry in the SQL coding, if that makes any sense. This in mind, how do I get the user's input from another form I've made for the user to input their user name and password to the main form to be used in SQL? I've got an idea behind that, but I figured I'd ask.
Follow the CodeBank link in my signature below and check out my WinForms Login thread. You might also like to follow the Blog link and check out my post on Parameters In ADO.NET for more info on the @ thing. There's also a series of blog posts on moving data between forms.
 Originally Posted by NFSRacer
Lastly, there is a requirement to allow for a user to switch tables within the database, however the project doesn't mention if it's required to keep it in the same form. Assuming it is required, how would I do that?
When you bind data to a DataGridView, it will automatically create columns by default. To switch tables you can unbind the old table, clear the columns and then bind the new table. If there's a BindingSource then you must unbind it from the grid. The columns are created when you set the DataSource property of the grid.
-
Nov 27th, 2013, 12:11 PM
#4
Thread Starter
Junior Member
Re: VB and SQL
Okay, so the scope of my problem is way bigger than I thought. How exactly do I go about trying to match login information -- that is, username and password -- to that of what's already in an SQL table? Or, in a better explanation, how do I take the username and password in two VB text boxes and compare it to those inside an SQL table to make it almost like logging into a website?...That might have just been a reiteration, but I'm EXTREMELY pressed for time for this project, and need to have it done just about yesterday...
-
Nov 27th, 2013, 05:55 PM
#5
Re: VB and SQL
I would create a connection object, then create a command object from that, then write a query that looked for the user name and password. It would look something like this, though I don't know enough (and don't want to know enough) to fully complete it:
Code:
Using cn as New SqlClient.SqlConnection(yourConnectionStringHere)
Using cmd as SqlClient.SqlCommand = cn.CreateCommand
Try
cn.Open
cmd.CommandText = "SELECT someFieldLikeThePrimaryKey FROM tableWithUsernamesAndPasswords WHERE Username = @p1 AND Password = @p2"
cmd.Parameters.AddWithValue("@p1",textboxWithUserName.Text)
cmd.Parameters.AddWithValue("@p2",textboxWithPassword.Text)
If cmd.ExecuteScalar Is Nothing Then
'It wasn't valid.
Else
'It was valid.
End If
Catch ex As Exception
'Do something here.
End Try
End Using
End Using
I'd probably have this in a method that returned a Boolean, so if it was valid I'd return True and if it was not valid I'd return False.
My usual boring signature: Nothing
 
-
Nov 27th, 2013, 08:52 PM
#6
Re: VB and SQL
 Originally Posted by NFSRacer
Okay, so the scope of my problem is way bigger than I thought. How exactly do I go about trying to match login information -- that is, username and password -- to that of what's already in an SQL table? Or, in a better explanation, how do I take the username and password in two VB text boxes and compare it to those inside an SQL table to make it almost like logging into a website?...That might have just been a reiteration, but I'm EXTREMELY pressed for time for this project, and need to have it done just about yesterday...
You would do what I already told you to do and read my CodeBank thread on the subject. We post threads in the CodeBank specifically so we don't have to keep providing the same information for the same questions over and over. I'm not fond of reiteration myself so you probably ought to read the answer provided and follow the advice it contains.
-
Dec 1st, 2013, 08:24 PM
#7
Thread Starter
Junior Member
Re: VB and SQL
 Originally Posted by jmcilhinney
You would do what I already told you to do and read my CodeBank thread on the subject. We post threads in the CodeBank specifically so we don't have to keep providing the same information for the same questions over and over. I'm not fond of reiteration myself so you probably ought to read the answer provided and follow the advice it contains.
Well, I know you keep mentioning that, but having my questions directly answered, instead of having to sift through data, saves me more time than you think. As it stands, I'm running into more roadblocks.
For starters, I'm now trying to figure out how to have a ComboBox load in its collection from a database's table, without inserting, updating, or deleting any entries. How exactly do I do that?
-
Dec 1st, 2013, 08:40 PM
#8
Re: VB and SQL
Oh, I see. I didn't realise that your time was so much more important than mine. I thought that I could put examples in one thread and then everyone who needed those examples could just look there but now I see that it would be far more trouble for you to click that link and spend a couple of minutes reading than it would be for me to keep providing the same information over and over again, hundreds of times. How selfish of me. Please accept my apologies.
As for your new question, follow the CodeBank link in my signature and check out my thread on Retrieving & Saving Data, which includes an example of retrieving data that doesn't need to be updated. I probably should have directed you to that thread in the first place because, if you'd already read it, then you wouldn't even need to ask that last question because you'd already know.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|