how do i add records into my sql ce table. i dont have a dataset so i cant use my other sql sample.
Printable View
how do i add records into my sql ce table. i dont have a dataset so i cant use my other sql sample.
answered my own question. found this on a microsoft siteVB Code:
'Create a SqlCeCommand on your connection Dim insertCommand As SqlCeCommand = sqlConn.CreateCommand() 'Set the CommandText for the command 'The ?'s represent parameters that will be set later insertCommand.CommandText = "Insert Into People(f_name, l_name) Values (?,?)" 'Add parameters and assign them the values from the TextBoxes on the form insertCommand.Parameters.Add(New SqlCeParameter("f_name", SqlDbType.NText, 50)) insertCommand.Parameters.Add(New SqlCeParameter("l_name", SqlDbType.NText, 50)) insertCommand.Parameters("f_name").Value = txtFName.Text insertCommand.Parameters("l_name").Value = txtLName.Text
i'd recommend once you have added all the parameters the .prepare method on the sqlcommand
insertCommand.Prepare()
insertCommand.ExecuteNonQuery()
what is prepare?
its sort of precompiles the sql statement so if there are any mismatches in datatype or data type lengths it will throw an exception before actually attempting to insert to the database and then throwing the exception.
it is just more efficient and faster, especially if you are inserting many records at a time