Reputation: 21
The error is 'Sqlexception was unhanded ' There was an error parsing the query. [ Token line number = 1,Token line offset = 8,Token in error = * ]
Dim con As SqlCeConnection = New SqlCeConnection("Data Source = C:\Users\vineet\Documents\Visual Studio 2010\Projects\sqlProject\sqlProject\studentDB.sdf")
Dim dcmd As SqlCeCommand
Dim da As SqlCeDataAdapter
Dim ds As DataSet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' ShowData()
End Sub
Public Sub ShowData()
dcmd = New SqlCeCommand("Select * FROM studentTable", con)
If con.State = ConnectionState.Closed Then con.Open()
'now we will populate the dataset with the help of data adapter
da = New SqlCeDataAdapter(dcmd)
ds = New DataSet()
da.Fill(ds, "MyTable")
DataGridStudents.DataSource = ds.Tables("MyTable").DefaultView
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
ShowData()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
dcmd = New SqlCeCommand("Delete * From studentTable Where name=@name", con)
dcmd.Parameters.AddWithValue("@name", TextBox6.Text)
If con.State = ConnectionState.Closed Then con.Open()
dcmd.ExecuteNonQuery()
ShowData()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dcmd = New SqlCeCommand("Insert Into studentTable(ID,name,address,mobile,email) Values(@fID,@fname,@faddress,@fmobile,@femail)")
dcmd.Parameters.AddWithValue("@ID", TextBox1.Text)
dcmd.Parameters.AddWithValue("@fname", TextBox1.Text)
dcmd.Parameters.AddWithValue("@faddress", TextBox1.Text)
dcmd.Parameters.AddWithValue("@fmobile", TextBox1.Text)
dcmd.Parameters.AddWithValue("@femail", TextBox1.Text)
If con.State = ConnectionState.Closed Then con.Open()
dcmd.ExecuteNonQuery()
ShowData()
End Sub
End Class
Upvotes: 0
Views: 274
Reputation: 5719
It should be ..
dcmd.Parameters.AddWithValue("@fID", TextBox1.Text)
and it should be ..
dcmd = New SqlCeCommand("Insert Into studentTable(ID,name,address,mobile,email) Values(@fID,@fname,@faddress,@fmobile,@femail)", con)
Upvotes: 1
Reputation: 34844
You are passing TextBox1.Text
for every parameter value.
dcmd.Parameters.AddWithValue("@ID", TextBox1.Text)
dcmd.Parameters.AddWithValue("@fname", TextBox1.Text)
dcmd.Parameters.AddWithValue("@faddress", TextBox1.Text)
dcmd.Parameters.AddWithValue("@fmobile", TextBox1.Text)
dcmd.Parameters.AddWithValue("@femail", TextBox1.Text)
I am not sure from the code posted, what the names of the actual UI controls that need to map to each of the pieces of data are, but I am pretty sure TextBox1.Text
is not all of those in one.
Upvotes: 2