Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
GaryM_1983
Starting Member
10 Posts |
Posted - 2012-06-14 : 05:38:57
|
| Hello all,After some advice. I have followed this tutorial on youtube to the letter and for some reason my login does not work. I've tried it at least 5 times with no success! I am working with SQL2008 and VB Express 2010. Could someone please help this noob out!http://www.youtube.com/watch?v=p0dcPiLYrckPlease see following my coding from my VB page:Private Sub btnSubmit_Click(sender As System.Object, e As System.EventArgs) Handles btnSubmit.Click Dim Connection As New SqlClient.SqlConnection Dim Command As New SqlClient.SqlCommand Dim Adapter As New SqlClient.SqlDataAdapter Dim Dataset As New DataSet Connection.ConnectionString = ("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Classic Cars Dealership Database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True") Command.CommandText = "SELECT * FROM [tblStaff] WHERE Username = ' " & txtUsername.Text & " ' AND Password = ' " & txtPassword.Text & " ';" Connection.Open() Command.Connection = Connection Adapter.SelectCommand = Command Adapter.Fill(Dataset, "0") Dim Count = Dataset.Tables(0).Rows.Count If Count > 0 Then frmMainMenu.Show() Me.Hide() Else MsgBox("Incorrect Username and/or Password entered", MsgBoxStyle.Critical) txtUsername.Clear() txtPassword.Clear() txtUsername.Focus() End If End SubMy table name is definately correct as are the field names!Thanks in advance!GaryM_1983 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-06-14 : 05:59:49
|
| Does the connect succeed? The query will depend on access to the database and table not just the login to the server.Have yoou tried running the query outside the application to see if it returns anything frrom the table?==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
GaryM_1983
Starting Member
10 Posts |
Posted - 2012-06-14 : 06:08:52
|
| Hi nigelrivett,Yes, using the Data Sources window I can preview the data and this works successfully (is this what you mean?).ThanksGaryM_1983 |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-06-14 : 06:35:59
|
| No - I mean is the connection successful when you execute that code, does it execute thw query on the database and return a resultset?If so then the resultset is maybe empty in which case there isn't a matching row in the table.Another option is that the row count isn't available until the recordset pointer is set to the last row or the recordset is closed.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
GaryM_1983
Starting Member
10 Posts |
Posted - 2012-06-14 : 07:02:45
|
| By the look of it, it does not connect! Do you see why that would be?GaryM_1983 |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-06-14 : 07:35:05
|
| Then the Connection.Open() is failing. It should abort at this point.The connection string looks odd. Are you trying to attach a database to the server as part of the open?Would need to be detached before you run again.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
GaryM_1983
Starting Member
10 Posts |
Posted - 2012-06-14 : 08:03:51
|
| I'm not 100% sure what you mean. The database exists and I want to be able to access the next page of my program when valid information from the database is matched with that inputted by the user.Really sorry, I am new to this!GaryM_1983 |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-06-14 : 08:37:46
|
| Try leaving out the filename.Data Source=mymachinename\myinstancename;Initial Catalog=myDataBase;Integrated Security=SSPI==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|