Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!!!

Posted
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...