|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#16
|
|||
|
|||
|
There is already an open DataReader associated with this Command which must be closed first.
Line 30: lblName.Text = sqlNameCommand1.ExecuteScalar.ToString() [COLOR=Black]What does this mean? |
|
#17
|
||||
|
||||
|
Not to be flip, but exactly what it says. I'm guessing you may have forgotten to close the connection or trying to do the ExecuteReader whilst doing something else with the connection. Would need the surrounding code to tell.
BTW sqlNameCommand1.ExeucteScalar.ToString() is a VERY BAD thing to do (for a SELECT query anyway). If the command doesn't return any rows, it will return Nothing, and invoking a method on Nothing will cause an exception.
__________________
Wolffy ------------------------ Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary. Not FDIC insured |
|
#18
|
|||
|
|||
|
Code:
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim sqlConnect As System.Data.SqlClient.SqlConnection
Dim sqlCommandDB As System.Data.SqlClient.SqlCommand
Dim customerName As String
Dim obj As Object
sqlConnect = New System.Data.SqlClient.SqlConnection("DataSource=.\SQLEXPRESS;AttachDbFilename=|DataDire ctory|\MediaDirect.mdf;Integrated Security=True;User Instance=True")
sqlCommandDB = New System.Data.SqlClient.SqlCommand("SELECT [name] FROM [Customer] WHERE [Username] = '" & txtUserName.Text & "' AND [Password] = '" & txtPassword.Text & "'")
Try
sqlConnect.Open()
obj = sqlCommandDB.ExecuteScalar
If (obj = Nothing) Then
lblError.Text = "Invalid Userid Or Password"
lblError.ForeColor = Drawing.Color.Red
lblName.Text = String.Empty
Else
lblName.Text = String.Format("Welcome {0} To Media Direct", Convert.ToString(obj))
lblError.Text = String.Empty
End If
Catch ex As Exception
lblError.Text = "Oops, something bad happened, call the administrator"
Finally
sqlConnect.Close()
|
|
#19
|
||||
|
||||
|
So, exactly where in the code you posted is the line causing the error? The line you posted isn't in there.
|
|
#20
|
|||
|
|||
|
thats strange when i run the code i get this error but when i check the code the lines is not there
|
|
#21
|
|||
|
|||
|
the error message is coming from this souce file Default.aspx.vb. how do i update this file
|
|
#22
|
||||
|
||||
|
Aha! So VWD has code-behinds. Don't know in VWD, but in Visual Studio F7 opens the code-behind page.
|
|
#23
|
|||
|
|||
|
i open it and copied the code into their.
but the log in still doest work |
|
#24
|
|||
|
|||
|
i tried the code you provided
Code:
Protected Sub btnButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim sqlConnect As System.Data.SqlClient.SqlConnection
Dim sqlCommandDB As System.Data.sqlClient.sqlCommand
Dim customerName as String
Dim obj as Object
sqlConnect = New System.Data.SqlClient.SqlConnection(Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\MediaDirect.mdf;Integrated Security=True;User Instance=True")
sqlCommandDB = New System.Data.SqlClient.SqlConnection("SELECT [name] FROM [Customer] WHERE [Username] = '" txtUsername.Text & "' AND [Password] = '" txtPassword.Text & "'")
Try
sqlConnect.Open()
obj = sqlCommandDB.ExecuteScalar
If (obj = Nothing) Then
lblError.Text = "Invalid Userid Or Password"
lblError.ForeColor = Drawing.Color.Red
lblName.Text = String.Empty
dataCustomer.Visible = False
Else
lblName.Text = String.Format("Welcome {0} To Media Direct", Convert.ToString(obj))
dataCustomer.Visible = True
lblError.Text = String.Empty
End If
Catch ex as Exception
lblError.Text = "Oops, something bad happened, call the administrator"
Finally
sqlConnect.Close()
End Try
End Sub
it works but everytime i tried to login it displays "Oops, something bad happened, call the administrator" instead of the welcome note and their userid |
|
#25
|
||||
|
||||
|
Then something in the Try block is throwing an exception. To be honest, I probably put too much in the Try block -- the If..Then..Else should probably be outside.
Anyway put this into your Catch block rather than the cutesy message I provided: lblError.Text = ex.Message |
|
#26
|
|||
|
|||
|
any idea of what i should put in and where
|
|
#27
|
||||
|
||||
|
As I said, replace the 1 line of code in the Catch block with the 1 I provided.
Magic, I perceive that you are not much beyond the 'Hello World' stage in your ASP.NET development. I'm not trying to slam you here, but I think spending some time with the ASP.NET tutorials found lurking here an elsewhere on the web would pay off in the long run. Taking a look here would be a good place to start. Sure, we'll help you get past you current sticking spot, and we're here if you have any questions, of course. |
|
#28
|
|||
|
|||
|
i understood what u said and did that. the probelm was i copied it into the wrong file that i had backup. i really appreite your help.
|
|
#29
|
|||
|
|||
|
ive made alot changes and now need to know how to add a logout button once the user is login. is there a way to change the button once the user is login.
|
|
#30
|
||||
|
||||
|
Changing the text of a button is easy enough -- it has a Text property too. Curious tho what you expect to do during the logoff process?
|