|
Dave Kreskowiak wrote: I guess it was only inevitable that the "English" used to ask them followed.
Seems like it
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
A couple of points:
1. Your code is virtually unreadable. Putting <pre> tags around it would improve things.
2. Using Response.Write to render JavaScript code is bad practice. ASP.NET has the Page.ClientScriptManager class to assist with including script in your page output.
I don't know what is causing your problem because you haven't provided details of the error message.
Paul Marfleet
|
|
|
|
|
What a mess...
kc_renji wrote: System.Data.SqlClient.SqlDataReader has no instructor?
Read the error message again. That's not what it says.
Is there a syntax error?
No.
Dim conMbr As New SqlConnection
Don't create a connection object when you declare the reference. As you create another connection object when you open the connection, this first connection object is only created and then thrown away.
Dim cmdMbr As New SqlCommand
Don't create a command object when you declare the reference. As you create another command object when you specify the query, this first command object is only created and then thrown away.
Dim sqlReader As New SqlDataReader
You can't create a data reader using the new keyword, as there is no public constructor that can be used for that.
You shouldn't try to create a data reader object when you declare the reference. As you will be creating one when you execute the query, the first object would only be created and then thrown away.
strVerifyMbr = "SELECT MemberId FROM datMember WHERE memberUserName=@usrId AND memberPassword=@pwd"
If you have parameters in your query, you have to add parameter objects to the command object to provide their values.
While sqlReader.Read()
You have to create the data reader before you can read from it. Call the ExecuteReader method of the command object to execute the query and get the result in a data reader.
If txtLogin.Text=Convert.ToString(sqlReader("memberUsername"))Then
The data reader doesn't contain any field named "memberUsername", as you don't get any data from that field in the query.
If txtPwd.Text=Convert.ToString(sqlReader("memberPassword")) Then
The data reader doesn't contain any field named "memberPassword", as you don't get any data from that field in the query.
Session("password") = sqlReader("memberPassword")
Why are you storing the password in the session variables? Are you going to check the password against the database every time you want to check if the user is logged in?
Else
This will never happen. As you only get the user record from the database if the password is correct, you will never have any record in the data reader where the user name is correct and the password is wrong.
Response.Write("window.alert('Invalid Password. Please try again.');<" + "/script>")</blockquote>
Don't use JScript, that is only supported by Internet Explorer. Use Javascript.
Using Response.Write is not a good way of putting code in the page. It will place the code above the doctype, which will make the browser ignore the doctype and render the page in quirks mode.
<blockquote class="FQ">checkUsr="Failed"</blockquote>
This code will never be reached. If the user name or password is not correct, the data reader will be empty, and you will never enter the loop.
<blockquote class="FQ">If checkUsr ="Failed" Then</blockquote>
As the variable will never have that value, the code in the if statement will never be executed.
<div class="ForumSig"><small><small>---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams</small></small></div>
|
|
|
|
|
My Access database isn't being updated, but no errors occurred in my application
I have the following code in a class library:
Public Class clsSlaveBD
Dim strConString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Karate.mdb;Persist Security Info=True"
Public drSlave As OleDbDataReader
Public Function getConexao() As OleDbConnection
Return New OleDbConnection(strConString)
End Function
Public Sub login(ByVal inNome As String, ByVal inPass As String, ByVal inTipo As String)
Dim comLogin As New OleDbCommand("SELECT Nome, Password, Tipo FROM Utilizadores Where (Nome=@Nome AND Password=@Pass AND Tipo=@Tipo)")
With comLogin
.Connection = getConexao()
.Connection.Open()
.Parameters.Add(New OleDbParameter("@Nome", inNome))
.Parameters.Add(New OleDbParameter("@Pass", inPass))
.Parameters.Add(New OleDbParameter("@Tipo", inTipo))
drSlave = .ExecuteReader
End With
End Sub
Public Sub altpass(ByVal inNome As String, ByVal inPass As String, ByVal inNovPass As String)
Dim comAltPass As New OleDbCommand("UPDATE [Utilizadores] SET [Password]=@NovPass WHERE [Nome]=@Nome AND [Password]=@Pass")
With comAltPass
.Connection = getConexao()
.Connection.Open()
.Parameters.Add(New OleDbParameter("@Nome", inNome))
.Parameters.Add(New OleDbParameter("@Pass", inPass))
.Parameters.Add(New OleDbParameter("@NovPass", inNovPass))
drSlave = .ExecuteReader
End With
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class
And in the event click of a button in a windows form the following code:
Public Class frmAltPass
Public strNovPass As String
Private Sub cmdValPass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdValPass.Click
If txtPassAct.Text <> "" And txtNovPass.Text <> "" And txtConfPass.Text <> "" Then
If txtPassAct.Text = frmLogin.strPass And txtNovPass.Text = txtConfPass.Text Then
strNovPass = txtNovPass.Text
Dim clsSlaveBD As New BD_Slave.clsSlaveBD
clsSlaveBD.altpass(frmLogin.strUtil, frmLogin.strPass, strNovPass)
MsgBox("Password alterada com êxito", MsgBoxStyle.Information, "")
frmMDI.sbMsgAp.Text = ""
frmLogin.strPass = strNovPass
Me.Dispose()
Else
frmMDI.sbMsgAp.Text = "Erro na digitação das passwords. Reinsira a password."
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
ctl.Text = ""
End If
Next
End If
Else
MessageBox.Show("Todos os campos são de preenchimento obrigatório")
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox And ctl.Text = "" Then
ctl.Select()
End If
Next
End If
End Sub
End Class
Both the variables frmLogin.strUtil and frmLogin.strPass are defined as Public in frmLogin form.
The application shows no errors but the database isn't updating the table "Utilizadores".
Can someone help me, please.
I have the following code in a class library:
Public Class clsSlaveBD
Dim strConString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Karate.mdb;Persist Security Info=True"
Public drSlave As OleDbDataReader
Public Function getConexao() As OleDbConnection
Return New OleDbConnection(strConString)
End Function
Public Sub login(ByVal inNome As String, ByVal inPass As String, ByVal inTipo As String)
Dim comLogin As New OleDbCommand("SELECT Nome, Password, Tipo FROM Utilizadores Where (Nome=@Nome AND Password=@Pass AND Tipo=@Tipo)")
With comLogin
.Connection = getConexao()
.Connection.Open()
.Parameters.Add(New OleDbParameter("@Nome", inNome))
.Parameters.Add(New OleDbParameter("@Pass", inPass))
.Parameters.Add(New OleDbParameter("@Tipo", inTipo))
drSlave = .ExecuteReader
End With
End Sub
Public Sub altpass(ByVal inNome As String, ByVal inPass As String, ByVal inNovPass As String)
Dim comAltPass As New OleDbCommand("UPDATE [Utilizadores] SET [Password]=@NovPass WHERE [Nome]=@Nome AND [Password]=@Pass")
With comAltPass
.Connection = getConexao()
.Connection.Open()
.Parameters.Add(New OleDbParameter("@Nome", inNome))
.Parameters.Add(New OleDbParameter("@Pass", inPass))
.Parameters.Add(New OleDbParameter("@NovPass", inNovPass))
drSlave = .ExecuteReader
End With
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class
And in the event click of a button in a windows form the following code:
Public Class frmAltPass
Public strNovPass As String
Private Sub cmdValPass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdValPass.Click
If txtPassAct.Text <> "" And txtNovPass.Text <> "" And txtConfPass.Text <> "" Then
If txtPassAct.Text = frmLogin.strPass And txtNovPass.Text = txtConfPass.Text Then
strNovPass = txtNovPass.Text
Dim clsSlaveBD As New BD_Slave.clsSlaveBD
clsSlaveBD.altpass(frmLogin.strUtil, frmLogin.strPass, strNovPass)
MsgBox("Password alterada com êxito", MsgBoxStyle.Information, "")
frmMDI.sbMsgAp.Text = ""
frmLogin.strPass = strNovPass
Me.Dispose()
Else
frmMDI.sbMsgAp.Text = "Erro na digitação das passwords. Reinsira a password."
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
ctl.Text = ""
End If
Next
End If
Else
MessageBox.Show("Todos os campos são de preenchimento obrigatório")
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox And ctl.Text = "" Then
ctl.Select()
End If
Next
End If
End Sub
End Class
Both the variables frmLogin.strUtil and frmLogin.strPass are defined as Public Shared in frmLogin. The application shows no errors but the database isn't updating the table "Utilizadores".
Can someone help me, please.
|
|
|
|
|
I haven't read your post because, frankly, it's just way to freakin' long.
But, I take it that every time you run your application from inside the Visual Studio environment, the database looks like it's getting changed, but then you run it again and the changes are lost??
This is because the database .MDB file in your project is being copied to the Debug folder where your .EXE is being run from every time you run your code. Click on the file in the Solution Explorer and look at the Properties window. There's an option in there that says "Copy to Output Directory". Right now, it probably says "Copy Always". This is what's overwriting your changes in the database every time you run your app from inside Visual Studio.
|
|
|
|
|
Dave Kreskowiak wrote: I haven't read your post because, frankly, it's just way to freakin' long.
I scrolled through it and didn't bother looking at the code because it was too long (wanted to first see what I was up against)
"Find it your bloody self - immediately!" - Dave Kreskowiak
|
|
|
|
|
I apologize for extension of my previously post.
Answering your reply, let me tell you that before I submited my problem to this forum, I had allready verified that the propertie "Copy to Output Directory" of the .MDB file was set to "Do not Copy", so I don't think the problem is there.
Besides that, what do you think that could be the problem?
Let me thank you for your time sppending with this trivial to you, technical trouble.
David Manuel Pires
|
|
|
|
|
Verify the path to the database file actually being used in your code.
The most common cause of the problem is what I already described.
Beyond that, the problem is in your code, but with no code snippet doing the update and no exception messages (you're not just eating them in a Try/Catch block are you??) there's little that anyone can tell you.
One thing does come to mind. In your UPDATE SQL verify that you are supplying the correct UDPATE, INSERT, and DELETE statements that will work on just ONE record in the WHERE clause.
|
|
|
|
|
The path is correct, and the SQL instruction is also correct. I've tried it directly against the database and it update the table without a problem.
Also, I'm not bot using a Try/Catch block, and I'm not receiving any exceptions from the application.
What do you mean by "code snippet"?
Again, I thank you a lot.
David Manuel Pires
|
|
|
|
|
Post only the portion of code where you suspect the problem, and not the whole thing.
"Find it your bloody self - immediately!" - Dave Kreskowiak
|
|
|
|
|
Sorry for the extension of my previous post. The portion of the code is:
Public Class clsSlaveBD
Dim strConString As String = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=|DataDirectory|\Karate.mdbersist Security Info=True"
Public drSlave As OleDbDataReader
Public Function getConexao() As OleDbConnection
Return New OleDbConnection(strConString)
End Function
Public Sub altpass(ByVal inNome As String, ByVal inPass As String, ByVal inNovPass As String)
Dim comAltPass As New OleDbCommand("UPDATE [Utilizadores] SET [Password]=@NovPass WHERE [Nome]=@Nome AND [Password]=@Pass")
With comAltPass
.Connection = getConexao()
.Connection.Open()
.Parameters.Add(New OleDbParameter("@Nome", inNome))
.Parameters.Add(New OleDbParameter("@Pass", inPass))
.Parameters.Add(New OleDbParameter("@NovPass", inNovPass))
drSlave = .ExecuteReader
End With
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class
Public Class frmAltPass
Public strNovPass As String
Private Sub cmdValPass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdValPass.Click
If txtPassAct.Text <> "" And txtNovPass.Text <> "" And txtConfPass.Text <> "" Then
If txtPassAct.Text = frmLogin.strPass And txtNovPass.Text = txtConfPass.Text Then
strNovPass = txtNovPass.Text
Dim clsSlaveBD As New BD_Slave.clsSlaveBD
clsSlaveBD.altpass(frmLogin.strUtil, frmLogin.strPass, strNovPass)
end sub
Can you help me?
David Manuel Pires
end class
|
|
|
|
|
I don't mean to nit-pick, but plaintext passwords are a really bad idea.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I agree with you, it's not a good idea, but my problem still remains. Do you have any other suggestions?
David Manuel Pires
|
|
|
|
|
I've solved it.
The problem was in the order i was adding the parameters to the OleDbCommand, I wasn't doing it in the same order they where in the UPDATE statement.
So I change the code from:
ublic Sub altpass(ByVal inNome As String, ByVal inPass As String, ByVal inNovPass As String)
Dim comAltPass As New OleDbCommand("UPDATE [Utilizadores] SET [Password]=@NovPass WHERE [Nome]=@Nome AND [Password]=@Pass")
With comAltPass
.Connection = getConexao()
.Connection.Open()
.Parameters.Add(New OleDbParameter("@Nome", inNome))
.Parameters.Add(New OleDbParameter("@Pass", inPass))
.Parameters.Add(New OleDbParameter("@NovPass", inNovPass))
.ExecuteNonQuery()
End With
End Sub
to:
Public Sub altpass(ByVal inNome As String, ByVal inPass As String, ByVal inNovPass As String)
Dim comAltPass As New OleDbCommand("UPDATE [Utilizadores] SET [Password]=@NovPass WHERE [Nome]=@Nome AND [Password]=@Pass")
With comAltPass
.Connection = getConexao()
.Connection.Open()
.Parameters.Add(New OleDbParameter("@NovPass", inNovPass))
.Parameters.Add(New OleDbParameter("@Nome", inNome))
.Parameters.Add(New OleDbParameter("@Pass", inPass))
.ExecuteNonQuery()
End With
End Sub
And it works just fine.
Anyway, I want to thank all of those who spent time trying to help me.
David Manuel Pires
|
|
|
|
|
Hello!
I have a collection with objects that are instances of the same class. The user can create and delete objects, so, the number of objects when the settings are saved is not the same. Moreover, the name of each object, which is also its SettigsKey, is given by the user. The setting values of all existing objects are saved correctly in the user.config file. Knowing a SettingsKey, I can retrieve the settings values from the user.config file and create the object. I would like to create objects for all “SettingsKeys” saved in the user.config file when the application starts.
So, How can I retrieve all the SettingsKey saved in the user.config file?
And, when the user deletes one object, how can I delete the settings values of the deleted object from the user.config file?
Thanks any help.
Umbelino
University of Minho, Portugal
|
|
|
|
|
You're really going to have a tough time doing this. Every user get's their own copy of the user.config file. The users settings are not all sotred in a single copy of the file. The user.config settings that you refer to are stored in the profile of each user. Normally, under the path:
C:\Documents and Settings\userId\Application Data\companyName\appName_evidenceType_evidenceHash\version\user.config
The users, unless an Administrator, cannot see inside the profile folder of another user, and therefore, cannot see the settings another user has defined.
|
|
|
|
|
Yes, I now all this. I am using My.Settings object to store and retrieve application settings and end-user preferences. The settings are stored in two files, app.config file and user.config file (for each user), which is stored in: “C:\Documents and Settings\<username>\Local Settings\Application Data”. When we have multiple instances of the same class they share the same settings class. We can solve this problem by using the SettingsKey property from the System.Configuration.ApplicationSettingsBase Class to define multiple sets of settings. You can see this here, "http://www.code-magazine.com/articleprint.aspx?quickid=0607031&printmode=true[^]". So, in this case, I would like to retrieve all the SettingsKey saved in the user.config file and, when the user deletes one object, I would like to delete the settings values of the deleted object from the user.config file.
Thanks one more time.
Umbelino
|
|
|
|
|
OleDbConnection ConVerify;
OleDbCommand CmdVerify;
OleDbDataReader DtrVerify;
string StrVerify;
ConVerify = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=Jigsaw.mdb");
ConVerify.Open();
StrVerify ="Select * From staff";
CmdVerify = new OleDbCommand(StrVerify,ConVerify);
DtrVerify =CmdVerify.ExecuteReader();
string checkuser="";
while(DtrVerify.Read())
{
if (txtusername.Text == Convert.ToString(DtrVerify["staff_username"]))
{
if(txtpassword.Text == Convert.ToString(DtrVerify["staff_password"]))
{
Session["username"]=DtrVerify["staff_username"];
Session["password"]=DtrVerify["staff_password"];
Server.Transfer("mainStaff.aspx");
}else
{
Response.Write("window.alert('Invalid Password! Please Try Again.');<"+"/SCRIPT>");
Server.Transfer("staffLogin.aspx");
}
}
checkuser="Failed";
}
if (checkuser=="Failed")
{
Response.Write("<SCRIPT lanquage='JScript'>window.alert('Invalid Username! Please Try Again.');<"+"/SCRIPT>");
Server.Transfer("staffLogin.aspx");
}
ConVerify.Close();
<div class="ForumSig">Life is up and down
Nevertheless,never give up hope and be confident to yourself</div>
|
|
|
|
|
|
Try it !
Dim ConVerify As OleDbConnection
Dim CmdVerify As OleDbCommand
Dim DtrVerify As OleDbDataReader
Dim StrVerify As String
ConVerify = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=Jigsaw.mdb")
ConVerify.Open()
StrVerify = "Select * From staff"
CmdVerify = New OleDbCommand(StrVerify, ConVerify)
DtrVerify = CmdVerify.ExecuteReader()
Dim checkuser As String = ""
While DtrVerify.Read()
If txtusername.Text = Convert.ToString(DtrVerify("staff_username")) Then
If txtpassword.Text = Convert.ToString(DtrVerify("staff_password")) Then
Session("username") = DtrVerify("staff_username")
Session("password") = DtrVerify("staff_password")
Server.Transfer("mainStaff.aspx")
Else
Response.Write("<SCRIPT lanquage='JScript'>window.alert('Invalid Password! Please Try Again.');<" + "/SCRIPT>")
Server.Transfer("staffLogin.aspx")
End If
End If
checkuser = "Failed"
End While
If checkuser = "Failed" Then
Response.Write("<SCRIPT lanquage='JScript'>window.alert('Invalid Username! Please Try Again.');<" + "/SCRIPT>")
Server.Transfer("staffLogin.aspx")
End If
ConVerify.Close()
AliAmjad(MCP)
|
|
|
|
|
I got a question here..
If Im using sql server 2005 database..
would da OleDb can be used and the code stil the same except the connection string?
Im js a beginner.
Thanks a lot
Life is up and down
Nevertheless,never give up hope and be confident to yourself
|
|
|
|
|
I have tried the code but I got a runtime error as belo
"Error 2 Type 'System.Data.SqlClient.SqlDataReader' has no constructors. C:\Documents and Settings\user\My Documents\Visual Studio 2005\Projects\CinemaTicketing\CinemaTicketing\MainPage.vb 39 13 CinemaTicketing"
What does it mean by no instructor??
Life is up and down
Nevertheless,never give up hope and be confident to yourself
|
|
|
|
|
kc_renji wrote: What does it mean by no instructor?
Read the error message again. It's talking about a constructor, not an instructor.
You can't create an SqlDataReader object by using the new keyword, as there is no public constructor that can be use for that. A data reader is created using the command object by calling the ExecuteReader method.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
Thanks.I have corrected it.
Life is up and down
Nevertheless,never give up hope and be confident to yourself
|
|
|
|
|
There are converters on the web that will do this for you. None of them are perfect, but they can get pretty close.
Really, what you posted is very easy to convert. All you have to do is look at any of the code samples on MSDN and they'll show you a piece of VB.NET and the equivilent C# code. Just look at the patterns of each line and you'll see that the majority of code converts quite easily.
|
|
|
|
|