|
-
Jul 25th, 2005, 03:21 PM
#1
Thread Starter
Addicted Member
[RESOLVED] add rows
how do i add records into my sql ce table. i dont have a dataset so i cant use my other sql sample.
-
Jul 25th, 2005, 03:23 PM
#2
Thread Starter
Addicted Member
Re: add rows
answered my own question. found this on a microsoft site
VB 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
-
Jul 27th, 2005, 04:56 AM
#3
Fanatic Member
Re: add rows
i'd recommend once you have added all the parameters the .prepare method on the sqlcommand
insertCommand.Prepare()
insertCommand.ExecuteNonQuery()
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Jul 27th, 2005, 07:50 AM
#4
Thread Starter
Addicted Member
-
Jul 27th, 2005, 07:56 AM
#5
Fanatic Member
Re: add rows
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
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|