magedassad
New member
- Joined
- Aug 28, 2011
- Messages
- 2
- Programming Experience
- 1-3
Hello, I'm not sure where my mistake is but I'm getting SqlException was unhandled by user code.
system.Data.SqlClient.SqlException: Incorrect syntax near (textbox values) on the sQuery.ExecuteNonQuery()
[XCODE]
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" id="Data Source=Database at godaddy; Initial Catalog=Database name; User ID=****; ">
Protected Sub btnRegister_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim fname As String = txtFname.Text
Dim lname As String = txtLname.Text
Dim grade As String = ddlGrade.SelectedValue
Dim phone As String = txtPhone.Text
Dim email As String = txtEmail.Text
Dim dob As String = txtDob.Text
Dim Emergency As String = txtEmergency.Text
Dim myconnection As New SqlConnection("Data Source=*****; Initial Catalog=****; User ID=****; Password=****;")
myconnection.Open()
Dim sQuery As New SqlClient.SqlCommand("INSERT INTO WinterRetreat2011(fname,lname, grade,phone,email, [Date of Birth],[emergency num]) VALUES('" & fname & "," & lname & "," & grade & "," & phone & "," & email & "," & dob & "," & Emergency & "'", myconnection)
sQuery.Connection = myconnection
sQuery.ExecuteNonQuery()
lblComplete.Text = "Registration has been completed successfully!!!"
lblComplete.Visible = True
txtFname.Text = ""
txtLname.Text = ""
ddlGrade.SelectedIndex = 0
txtPhone.Text = ""
txtEmail.Text = ""
txtDob.Text = ""
txtEmergency.Text = ""
End Sub
</script>
[/XCODE]
Any help is appreciated,
thanks.
system.Data.SqlClient.SqlException: Incorrect syntax near (textbox values) on the sQuery.ExecuteNonQuery()
[XCODE]
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" id="Data Source=Database at godaddy; Initial Catalog=Database name; User ID=****; ">
Protected Sub btnRegister_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim fname As String = txtFname.Text
Dim lname As String = txtLname.Text
Dim grade As String = ddlGrade.SelectedValue
Dim phone As String = txtPhone.Text
Dim email As String = txtEmail.Text
Dim dob As String = txtDob.Text
Dim Emergency As String = txtEmergency.Text
Dim myconnection As New SqlConnection("Data Source=*****; Initial Catalog=****; User ID=****; Password=****;")
myconnection.Open()
Dim sQuery As New SqlClient.SqlCommand("INSERT INTO WinterRetreat2011(fname,lname, grade,phone,email, [Date of Birth],[emergency num]) VALUES('" & fname & "," & lname & "," & grade & "," & phone & "," & email & "," & dob & "," & Emergency & "'", myconnection)
sQuery.Connection = myconnection
sQuery.ExecuteNonQuery()
lblComplete.Text = "Registration has been completed successfully!!!"
lblComplete.Visible = True
txtFname.Text = ""
txtLname.Text = ""
ddlGrade.SelectedIndex = 0
txtPhone.Text = ""
txtEmail.Text = ""
txtDob.Text = ""
txtEmergency.Text = ""
End Sub
</script>
[/XCODE]
Any help is appreciated,
thanks.