What is the problem? Is the program blowing up? Is it not returning rows? Is it returning wrong rows?
Smith5646
Junior Poster in Training
65 posts since Nov 2009
Reputation Points: 34
Solved Threads: 9
Skill Endorsements: 0
Maybe this helps you
In Solution Explorer right click on My Project to open it.
Then click on View Windows Settings is where you can adjust userlevel.
Gé48
Junior Poster in Training
63 posts since Apr 2010
Reputation Points: 11
Solved Threads: 10
Skill Endorsements: 0
Now I understand the issue but really don't have a good answer. The code in lines 2 - 17 look right to me.
I am assuming they type into txtUser and txtPass and then click OK which sends them into this sub.
I'm not sure what you are doing with lines 23 and 34 and if they are causing you problems somehow. I doubt it but thought it was worth mentioning.
Here are a couple things to try.
1) Write a quick block of code to retrieve all rows from the DB and see if the row in question shows up that way. You can also do a "select count(*) from tbl_user" to see how many rows it thinks are in the DB. If these work, it has to be something in the select.
2) See if the values in the DB have extra spaces or something at the end of them.
3) See if the values in your textboxes have extra spaces or something at the end of them.
4) If you have another way to access your DB, try doing the select command outside of your program to see if it returns the row.
Let me know what you find and we'll keep narrowing it down.
Smith5646
Junior Poster in Training
65 posts since Nov 2009
Reputation Points: 34
Solved Threads: 9
Skill Endorsements: 0
This has me baffled so bear with me for some stupid questions.
If you have 3 records in the DB and then add a 4th record, you say it does not find the 4th record.
If you exit the app and restart, does it find the 4th record?
If you add a 4th and 5th record, does it find the 4th record but not the 5th or does it not find either?
Smith5646
Junior Poster in Training
65 posts since Nov 2009
Reputation Points: 34
Solved Threads: 9
Skill Endorsements: 0
I'm totally confused now. Can you attach the .MDF file to this thread so I can look at it?
Smith5646
Junior Poster in Training
65 posts since Nov 2009
Reputation Points: 34
Solved Threads: 9
Skill Endorsements: 0
I didn't realize the .MDF is SQL server (should have looked at the connection statement closer). Right now I don't have access to a machine with SQL server. Can you export to something such as Access, Excel, .csv?
Smith5646
Junior Poster in Training
65 posts since Nov 2009
Reputation Points: 34
Solved Threads: 9
Skill Endorsements: 0
Is SQL client required? If not, I can try to rewriting using an OLEDB client, which I am more famillar with. But this will require you to test it due to your database being local.
Begginnerdev
Practically a Posting Shark
864 posts since Apr 2010
Reputation Points: 184
Solved Threads: 142
Skill Endorsements: 8
I just want an exported copy of the data that I can read. I can't open a .MDF.
Smith5646
Junior Poster in Training
65 posts since Nov 2009
Reputation Points: 34
Solved Threads: 9
Skill Endorsements: 0
I am totally lost on this and not sure how to help further. Did you try the other suggestions that I made earlier? What were the results (reply using the question numbers)?
Syntax in the below code will probably need tweeked because I am free typing and not using Studio to edit / verify.
1) Write a block of code to retrieve all rows from the DB and see if the row in question shows up that way.
Dim cmd As New SqlClient.SqlCommand("SELECT * FROM tbl_user", con)
cmd.Connection.Open()
Dim reader As SqlClient.SqlDataReader = cmd.ExecuteReader()
while reader.HasRows
messagebox.show(reader(1))
end while
2) Do a "select count(*) from tbl_user" to see how many rows it thinks are in the DB.
Dim cmd As New SqlClient.SqlCommand("SELECT count(*) FROM tbl_user", con)
cmd.Connection.Open()
Dim reader As SqlClient.SqlDataReader = cmd.ExecuteReader()
messagebox.show(reader(0))
3) See if the values in the DB have extra spaces or something at the end of them.
Try changing you inserts to be .TEXT.TRIM
4) See if the values in your textboxes have extra spaces or something at the end of them.
Try changing you selects to be .TEXT.TRIM
5) If you have another way to access your DB, see if it returns the row. For example, in visual studio you can "show table data".
Smith5646
Junior Poster in Training
65 posts since Nov 2009
Reputation Points: 34
Solved Threads: 9
Skill Endorsements: 0
Ok,try this.
This should work fine with SQL Server 2008
'Be sure to import System.Data.OleDB
Dim constr As String = "Provider=SQLOLEDB;Server=BRMS-SERVER;Database=CavsuDB;Integrated Security=SSPI"
Dim sstr As String = "SELECT username,password,category FROM tbl_user WHERE username='" & txtUser.Text & " AND password='" & txtPass.Text & "'"
Dim con As New OleDbConnection(constr)
Dim cmd As New OleDbCommand(sstr, con)
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim dt As New DataTable
Try
con.Open()
'Set the string to the data adapter
da.SelectCommand = cmd
da.Fill(ds, "GetData")
dt = ds.Tables("GetData")
If dt IsNot Nothing Then
If dt.Rows.Count > 0 Then
Main.Show()
Me.Hide()
If chkAdmin.Checked = True Then
cmd.CommandText = "SELECT username,password FROM tbl_user WHERE categor='Admin'"
da.SelectCommand = cmd
da.Fill(ds, ("adminUsers"))
dt.Clear()
dt = ds.Tables("adminUsers")
If dt IsNot Nothing Then
If dt.Rows.Count > 0 Then
Main.AddUserToolStripMenuItem.Enabled = True
Main.DocumentToolStripMenuItem.Enabled = True
Main.SubjectsToolStripMenuItem.Enabled = True
Main.FacultyToolStripMenuItem.Enabled = True
Main.DepartmentToolStripMenuItem.Enabled = True
Else
MsgBox("There was a problem retrieving the admin users.", MsgBoxStyle.OkOnly)
End If
Else
MsgBox("Admin table is empty.", MsgBoxStyle.OkOnly)
End If
ElseIf chkAdmin.Checked = False Then
cmd.CommandText = "SELECT username,password FROM tbl_user WHERE category='user'"
da.SelectCommand = cmd
da.Fill(ds, ("Users"))
dt.Clear()
dt = ds.Tables("Users")
If dt IsNot Nothing Then
If dt.Rows.Count > 0 Then
Main.AddUserToolStripMenuItem.Enabled = False
Main.DocumentToolStripMenuItem.Enabled = True
Main.SubjectsToolStripMenuItem.Enabled = False
Main.FacultyToolStripMenuItem.Enabled = False
Main.DepartmentToolStripMenuItem.Enabled = False
Else
MsgBox("There was a problem retrieving the users.", MsgBoxStyle.OkOnly)
End If
Else
MsgBox("User table is empty.", MsgBoxStyle.OkOnly)
End If
End If
Else
MsgBox("**USER NOT FOUND**", MsgBoxStyle.OkOnly)
End If
Else
MsgBox("Data table is empty.", MsgBoxStyle.OkOnly)
End If
Catch ex As Exception
MsgBox("Exception From: " & ex.Source & vbCrLf & ex.Message & vbCrLf & "Could not connect to server and retrieve data.", MsgBoxStyle.OkOnly)
End Try
End Sub
Begginnerdev
Practically a Posting Shark
864 posts since Apr 2010
Reputation Points: 184
Solved Threads: 142
Skill Endorsements: 8