:confused:
Hi friends,
I am new to this forum and posting my problem for the first time after getting stuck at a point and trying to resolve it for the last 5 days but all in vein
I am using Visual Basic 2008 express edition with inbuilt facility of SQl server database ( I hope it is sql server 2008)
My database name is "MyDatabase" and the table name is "User" and is created in the project itself
Login Form
Public Class LoginForm
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strUserName As String = Me.txtUsername.Text
Dim strPassword As String = Me.txtPassword.Text
If strUserName = "" Or strPassword = "" Then
MessageBox.Show("You are missing information. Please make sure that both the username and password fields are filled out.", "Missing Info")
Me.txtUsername.Focus()
Return
End If
'Create a new connection object and assign the ConString Connection String above
Dim dbConn As New SqlClient.SqlConnection
Dim cmd As New SqlClient.SqlCommand
Dim adptr As New SqlClient.SqlDataAdapter
Dim ds As New DataSet
'The connection string is used to describe the type of database, the security information and the location to the database.
dbConn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True;User Instance=True"
cmd.CommandText = "SELECT Password FROM [User] WHERE Username= '" & strUserName & "' AND Password='" & strPassword & "';"
dbConn.Open()
cmd.Connection = dbConn
adptr.SelectCommand = cmd
adptr.Fill(ds, "0")
Dim count = ds.Tables(0).Rows.Count
If count > 0 Then
Form2.Show()
Me.Hide()
Else
MsgBox("Invalid login, Please check username and password")
txtPassword.Clear()
txtUsername.Clear()
End If
End Sub
End Class
My first form is running fine and comparing the data from database for logging in successfully
Form2
Imports System.Data.SqlClient
Public Class Form2
Private Sub btnChangePass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChangePass.Click
Dim ds As New DataSet
Dim connection As New SqlConnection
Dim adapter As SqlDataAdapter
Dim DAUpdateCmd As SqlCommand
'Set the connection string of the SqlConnection object to connect to the
'SQL Server database in which User table is created.
connection.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True;User Instance=True"
connection.Open()
'Initialize the SqlDataAdapter object by specifying a Select command
'that retrieves data from the User table.
adapter = New SqlDataAdapter("SELECT * FROM [User]", connection)
'Initialize the SqlCommand object that will be used as the DataAdapter's UpdateCommand.
'Note that the WHERE clause uses only the CustId field to locate the record that is to be updated.
DAUpdateCmd = New SqlCommand("UPDATE [User] SET Password='" & txtNewPass1.Text & "' WHERE Username='" & LoginForm.txtUsername.Text & "'",adapter.SelectCommand.Connection)
'Assign the SqlCommand to the UpdateCommand property of the SqlDataAdapter.
adapter.UpdateCommand = DAUpdateCmd
'note : Mydatabase is a database name , I hv tried table name "User" also in the next two commands
adapter.Fill(ds, "MyDatabase")
adapter.Update(ds, "MyDatabase")
MsgBox("Password updated successfully")
connection.Close()
LoginForm.show()
me.hide()
End Sub
End Class
When I run the program neither it is showing any error nor throwing any kind of exception, it accepts the changed password and goes to Form2 with new password.
BUT, if I close the application and restart or view the records of my table "User" in "MyDatabase" , it shows only old password...i.e. changes are not reflected in the database
I hv tried another Method Using Stored Procedure as under with another code snippet with the same problem
ALTER Procedure ProcInsertClass(@Division nvarchar(3), @Roomnum int, @Slotid nchar(3) )
as begin
insert into dbo.Class
values(@Division, @Roomnum, @Slotid)
end
Running this Procedure as sql Query in the database updates the database but calling the procedure in the form by passing 3 values as parameters shows insertion only till the application is not restarted. (No error or exception caught)
Same problem while using dataset and adaptor containers .
Please, it would be a great help if some body could guide me , if i am missing some thing like "COMMIT" as we use in oracle. Or if there is some other way
thanx
Hi friends,
I am new to this forum and posting my problem for the first time after getting stuck at a point and trying to resolve it for the last 5 days but all in vein
I am using Visual Basic 2008 express edition with inbuilt facility of SQl server database ( I hope it is sql server 2008)
My database name is "MyDatabase" and the table name is "User" and is created in the project itself
Login Form
Public Class LoginForm
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strUserName As String = Me.txtUsername.Text
Dim strPassword As String = Me.txtPassword.Text
If strUserName = "" Or strPassword = "" Then
MessageBox.Show("You are missing information. Please make sure that both the username and password fields are filled out.", "Missing Info")
Me.txtUsername.Focus()
Return
End If
'Create a new connection object and assign the ConString Connection String above
Dim dbConn As New SqlClient.SqlConnection
Dim cmd As New SqlClient.SqlCommand
Dim adptr As New SqlClient.SqlDataAdapter
Dim ds As New DataSet
'The connection string is used to describe the type of database, the security information and the location to the database.
dbConn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True;User Instance=True"
cmd.CommandText = "SELECT Password FROM [User] WHERE Username= '" & strUserName & "' AND Password='" & strPassword & "';"
dbConn.Open()
cmd.Connection = dbConn
adptr.SelectCommand = cmd
adptr.Fill(ds, "0")
Dim count = ds.Tables(0).Rows.Count
If count > 0 Then
Form2.Show()
Me.Hide()
Else
MsgBox("Invalid login, Please check username and password")
txtPassword.Clear()
txtUsername.Clear()
End If
End Sub
End Class
My first form is running fine and comparing the data from database for logging in successfully
Form2
Imports System.Data.SqlClient
Public Class Form2
Private Sub btnChangePass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChangePass.Click
Dim ds As New DataSet
Dim connection As New SqlConnection
Dim adapter As SqlDataAdapter
Dim DAUpdateCmd As SqlCommand
'Set the connection string of the SqlConnection object to connect to the
'SQL Server database in which User table is created.
connection.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True;User Instance=True"
connection.Open()
'Initialize the SqlDataAdapter object by specifying a Select command
'that retrieves data from the User table.
adapter = New SqlDataAdapter("SELECT * FROM [User]", connection)
'Initialize the SqlCommand object that will be used as the DataAdapter's UpdateCommand.
'Note that the WHERE clause uses only the CustId field to locate the record that is to be updated.
DAUpdateCmd = New SqlCommand("UPDATE [User] SET Password='" & txtNewPass1.Text & "' WHERE Username='" & LoginForm.txtUsername.Text & "'",adapter.SelectCommand.Connection)
'Assign the SqlCommand to the UpdateCommand property of the SqlDataAdapter.
adapter.UpdateCommand = DAUpdateCmd
'note : Mydatabase is a database name , I hv tried table name "User" also in the next two commands
adapter.Fill(ds, "MyDatabase")
adapter.Update(ds, "MyDatabase")
MsgBox("Password updated successfully")
connection.Close()
LoginForm.show()
me.hide()
End Sub
End Class
When I run the program neither it is showing any error nor throwing any kind of exception, it accepts the changed password and goes to Form2 with new password.
BUT, if I close the application and restart or view the records of my table "User" in "MyDatabase" , it shows only old password...i.e. changes are not reflected in the database
I hv tried another Method Using Stored Procedure as under with another code snippet with the same problem
ALTER Procedure ProcInsertClass(@Division nvarchar(3), @Roomnum int, @Slotid nchar(3) )
as begin
insert into dbo.Class
values(@Division, @Roomnum, @Slotid)
end
Running this Procedure as sql Query in the database updates the database but calling the procedure in the form by passing 3 values as parameters shows insertion only till the application is not restarted. (No error or exception caught)
Same problem while using dataset and adaptor containers .
Please, it would be a great help if some body could guide me , if i am missing some thing like "COMMIT" as we use in oracle. Or if there is some other way
thanx