rawky76 Posted May 29, 2005 Posted May 29, 2005 OK, here's my code: - Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click Dim sFN As String Dim sLN As String Dim sJT As String Dim sUN As String Dim sPW As String sFN = txtFirstName.Text.ToString sLN = txtLastName.Text.ToString sJT = txtJobTitle.Text.ToString sUN = txtUserName.Text.ToString sPW = txtPassword.Text.ToString Const sConnection As String = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=HelpdeskApp;Data Source=MARK" Dim objConn As New System.Data.OleDb.OleDbConnection(sConnection) objConn.Open() Dim sSQL As String Dim objCmd As New System.Data.OleDb.OleDbCommand(sSQL, objConn) sSQL = "INSERT INTO STAFF (First Name, Last Name, Username, Password, Job Title, StaffID) VALUES (sFN, sLN, sUN, sPW, sJT, 1)" Try objCmd.ExecuteNonQuery() Catch myException As System.Exception Console.WriteLine(myException.Message) End Try txtFirstName.Text = "" txtLastName.Text = "" txtJobTitle.Text = "" txtUserName.Text = "" txtPassword.Text = "" txtConfirmPassword.Text = "" End Sub No errors are thrown but nothing appears in the database!!?? Thanks for any help!!! Quote
Administrators PlausiblyDamp Posted May 29, 2005 Administrators Posted May 29, 2005 If you step through the code does everything seem to work fine? If you check the return value when you call ExecuteNonQuery() what value is returned from the call? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Blokz Posted May 30, 2005 Posted May 30, 2005 OK, here's my code: - Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click Dim sFN As String Dim sLN As String Dim sJT As String Dim sUN As String Dim sPW As String sFN = txtFirstName.Text.ToString sLN = txtLastName.Text.ToString sJT = txtJobTitle.Text.ToString sUN = txtUserName.Text.ToString sPW = txtPassword.Text.ToString Const sConnection As String = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=HelpdeskApp;Data Source=MARK" Dim objConn As New System.Data.OleDb.OleDbConnection(sConnection) objConn.Open() Dim sSQL As String Dim objCmd As New System.Data.OleDb.OleDbCommand(sSQL, objConn) sSQL = "INSERT INTO STAFF (First Name, Last Name, Username, Password, Job Title, StaffID) VALUES (sFN, sLN, sUN, sPW, sJT, 1)" Try objCmd.ExecuteNonQuery() Catch myException As System.Exception Console.WriteLine(myException.Message) End Try txtFirstName.Text = "" txtLastName.Text = "" txtJobTitle.Text = "" txtUserName.Text = "" txtPassword.Text = "" txtConfirmPassword.Text = "" End Sub No errors are thrown but nothing appears in the database!!?? Thanks for any help!!! 2 things. First, you dim sSQL as string, tie it to objCmd and THEN set the value of sSQL. Try this instead: Dim sSQL As String = "INSERT INTO STAFF (First Name, Last Name, Username, Password, Job Title, StaffID) VALUES (sFN, sLN, sUN, sPW, sJT, 1)" Next, if you are going to use variables as your VALUES in the insert statement, you need to build your sSQL string to use them. You have the variable names in the string, but your not using the values of those variables. Try this: Dim sSQL As String = "INSERT INTO STAFF (First Name, Last Name, Username, Password, Job Title, StaffID) VALUES ('" & sFN & "','" & sLN & "','" & sUN & "','" & sPW & "','" & sJT & "', 1)" Hope that helps, Blokz Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.