hey all,
I'm using a form to throw info straight into a database. i know it isn't the best way but i'm new and all other implementations have confused me (i've been reading and watching tutorials for 2 weeks) but anyway i'm going to take the info straight from the form.
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class frmClassAdd
Dim m_intClassId As Integer = 0
#Region " Form Controls & Events "
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
If ValidateData() <> True Then Exit Sub
Call AddClassRecord()
Call AddClass2db()
Me.Close()
End Sub
#End Region 'Form Controls & Events
'Contains submit and cancel buttons
#Region " Form Subs & Functions "
Private Sub AddClassRecord()
Dim row As DataRow = Nothing
row = g_dsGradeList.Classes.NewRow
row("ClassId") = nudClassId.Value
row("ClassName") = txtClassName.Text.Trim
row("Department") = txtDepartment.Text.Trim
g_dsGradeList.Classes.Rows.Add(row)
End Sub
Private Sub AddClass2db()
'this block below is to add the record straight into the database when
'the user inserts the validated info
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim ra As Integer 'integer holds the number of records inserted
Dim ClassId As String
Dim ClassName As String
Dim Department As String
'you need to provide password for sql server
myConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Ein05\Documents\dbGradeListApplication.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
myConnection.Open()
myCommand = new SqlCommand INSERT INTO tblClasses (ClassId,ClassName,Department)VALUES "('" + nudClassId.Value + "," +txtClassName.Text + "," + txtDepartment.Text "')";
ra = myCommand.ExecuteNonQuery()
MessageBox.Show("New Row Inserted" & ra)
myConnection.Close()
End Sub
but the only problem i'm coming into is where the line
myCommand = new SqlCommand INSERT INTO tblClasses (ClassId,ClassName,Department)VALUES "('" + nudClassId.Value + "," +txtClassName.Text + "," + txtDepartment.Text "')";
comes into play.
the error states that
End of statement expected.
i've been overlooking this over and over but i can't find my error.
help?