none
Adding a new record to a SQLServerCE dB table

    Question

  • Hi,

    With a lot of help from here, I learned where to find data saved to a bound table. Is there a way using VB Express to add a record to a bound table without clicking the add new record button first? I want to have a form just to add new data. I want the user to pull up the form from a switchboard, type in new data, click save, and the data be saved.

    Thanks,

    Ralph65

    Monday, March 19, 2012 12:46 PM

All replies

  • It's all depends on when will the data be saved/added.

    I made a demo in this thread that using a form (with TextBoxes on it ) to collect data and once the button "SAVE" is clicked, save the data to database, and also update the DataGridView which is used to show the table in the database. http://social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/c76c494d-0d30-4d4d-9e2d-e74f2004a721, hope this helps.

    If this is not what you want, please elaborate more clearly about the question with the information about what controls and when do you want the data be added.

    Sincerely,

    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, March 21, 2012 2:20 AM
  • Hi, Helen,

    That's exactly what I want, but, at least to me, it seems like you are doing the work yourself (which is what I am used to). I thought with bound controls VB saved the data for you. I guess to get that, you have use the add button.

    This brings up another question: I have written code similar to yours (using Access 2010). I wanted to convert it to work with its SQLServerCE counterpart. I added the reference to System.data.SqlServerCe.dll. Everything converted with no problems, except the dataadapter. When I  declared a variable as SqlCeDataAdapter, "SqlCeDataAdapter" gets a line under it. When I hover over "SqlCeDataAdapter", it says something about add reference to System.Data.Common. I typed imports...and System.Data.Common came up, so it must be referenced, right? How do I declare a variable SqlCeDataAdapter?

    Thank you,

    Ralph65

    Thursday, March 22, 2012 10:46 PM
  • Yes, please check the demo and related document here: http://msdn.microsoft.com/en-us/library/system.data.sqlserverce.sqlcedataadapter(v=vs.100).aspx

    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 26, 2012 3:35 AM
  • Hi, Helen,

    That's exactly what I want, but, at least to me, it seems like you are doing the work yourself (which is what I am used to). I thought with bound controls VB saved the data for you. I guess to get that, you have use the add button.

    This brings up another question: I have written code similar to yours (using Access 2010). I wanted to convert it to work with its SQLServerCE counterpart. I added the reference to System.data.SqlServerCe.dll. Everything converted with no problems, except the dataadapter. When I  declared a variable as SqlCeDataAdapter, "SqlCeDataAdapter" gets a line under it. When I hover over "SqlCeDataAdapter", it says something about add reference to System.Data.Common. I typed imports...and System.Data.Common came up, so it must be referenced, right? How do I declare a variable SqlCeDataAdapter?

    Thank you,

    Ralph65

    hi Ralph

    you mentioned you added the Reference to SqlServerCe.dll

    did you also Import the Namespace at the top of your code?

    Imports System.Data.SqlServerCe

    Monday, March 26, 2012 4:29 PM
  • Hi, Helen,

    Here are my declarations

    Imports System.Data.SqlServerCe

    Public Class frmAddBird

        Dim con As New SqlCeConnection()
        Dim cmd As New SqlCeCommand()
        Dim da As New SqlCeDataAdapter()
        Dim cb As SqlCeCommandBuilder
        Dim dr As DataRow
        Dim dt As New DataTable()
        Dim strConn As String

    As I mentioned, the "SqlCeDataAdapter" gets a wavy line under it (none of the others do), and when I hover over it, it says

    Reference required to assembly 'System.Data.Common,Version=1.0.5000.0,Culture=neutral, PublicKeyToken = 969db8053d3322ac, Retargetable= Yes' containing the base class 'System.Data.Common.DbDataAdapter'. Add one to your project.

    I added Imports System.Data.Common.DbDataAdapter, and it did not make a difference. What is going on?

    Thanks, Ralph65

    Friday, March 30, 2012 4:18 AM