Results 1 to 5 of 5

Thread: [RESOLVED] add rows

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    162

    Resolved [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.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    162

    Re: add rows

    answered my own question. found this on a microsoft site
    VB Code:
    1. 'Create a SqlCeCommand on your connection
    2.         Dim insertCommand As SqlCeCommand = sqlConn.CreateCommand()
    3.  
    4.         'Set the CommandText for the command
    5.         'The ?'s represent parameters that will be set later
    6.         insertCommand.CommandText = "Insert Into People(f_name, l_name) Values (?,?)"
    7.  
    8.         'Add parameters and assign them the values from the TextBoxes on the form
    9.         insertCommand.Parameters.Add(New SqlCeParameter("f_name", SqlDbType.NText, 50))
    10.         insertCommand.Parameters.Add(New SqlCeParameter("l_name", SqlDbType.NText, 50))
    11.  
    12.         insertCommand.Parameters("f_name").Value = txtFName.Text
    13.         insertCommand.Parameters("l_name").Value = txtLName.Text

  3. #3
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    162

    Re: add rows

    what is prepare?

  5. #5
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    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
  •  



Click Here to Expand Forum to Full Width