i did a simple login system which make use of a offline database using this tutorial.. http://www.youtube.com/watch?v=p0dcPiLYrck can anyone help me by adding a new user function to the program? +rep to anyone that can help me thanks tharoux in advance XD XD here is the source code.
Hi ! First, some advices... XD I watched the videos, and you can do all this with ALOT less code. -By using "Imports System.Data.SqlClient" at the very top of the code, you'll be able to skip all the "sqlClient." in the entire code. -I traded the "adaptor" for a SqlDataReader, it's lighter and faster to use cause it's read-only Here's how I would do it. This code assume you use the same table as in the video. It will add a record (using the "INSERT INTO" sql command) and than show all the records in the database to confirm yours was added. BTW, executeNonQuery() will return the numbers of record added. Usefull if you add more than one at once. The executeReader() will return a DataReader, usefull to read the content like I said previously. Code (Text): Imports System.Data.SqlClient Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim connection As SqlConnection Dim command As SqlCommand Dim datareader As SqlDataReader connection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Members.mdf;Integrated Security=True;User Instance=True") connection.Open() command = New SqlCommand("INSERT INTO [User] VALUES ('testing1','testing2');", connection) command.ExecuteNonQuery() command = New SqlCommand("SELECT * FROM [User];", connection) datareader = command.ExecuteReader() While datareader.Read() MsgBox(datareader(0).ToString) MsgBox(datareader(1).ToString) MsgBox(datareader(2).ToString) End While datareader.Close() connection.Close() End Sub End Class
lol knew u were gonna be the first.. alright sure..will try it and get back to u once i go on my laptop..(currently using my desktop which is programming-free XD) Still need the New User function - to the other 3 who dl the file..
the new user function is in there You're not expecting someone to give it already made ? it's too easy :maha:
LOL !..opps didn't even read the code when i was on my desktop and i misread what u typed .. sooo sorry..gonna try that out. will update if i meet with any problem.. edited : tried it out.. actually i wan the values to be entered from textbox1 and textbox2 .. the values can't be stored into the table? i am able to log in using the values : testing1, testing2 but the table doesn't show these two values in the respective columns..anyway to do that? 2nd edit : ha Code (Text): command = New SqlClient.SqlCommand("INSERT INTO [User](Username, Password) VALUES ('" & TextBox1.Text & "', '" & TextBox2.Text & "');", connection) the program can now add a new username & password temporarily..as specified by me in textbox1 and textbox2.. the problem is that the table won't be updated and after restarting the program, the new user that i created was gone..
Sorry, I missed your post because you only edited it. I don't have VB with me right now but there's an UPDATE function somewhere that should be put before the connection.close() but after the "INSERT INTO".
its alright ..yeah, i saw that function online before but i tried putting it here and there and it doesn't work.. can u take a look at the program again and maybe tell me where to put it ..i tried putting it right before close.connection, doesn't give any error but it still doesn't update the table. btw, if i were to use the SET function, will it be easier? i found this online Code (Text): UPDATE Persons SET Address='Nissestien 67', City='Sandnes' WHERE LastName='Tjessem' AND FirstName='Jakob' which will give P_Id LastName FirstName Address City 1 Hansen Ola Timoteivn 10 Sandnes 2 Svendson Tove Borgvn 23 Sandnes 3 Pettersen Kari Storgt 20 Stavanger 4 Nilsen Johan Bakken 2 Stavanger 5 Tjessem Jakob Nissestien 67 Sandnes meaning if i were to program mine, it would be something like this Code (Text): UPDATE [Users] SET Username='ABC', Password='123' WHERE ID='?' what do i put for the ID in order to user and pass under the correct ID number. oh ya, aha coming on to NF during work !!! XD XD ..