Vb 2008

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dellboymash
    New Member
    • Feb 2008
    • 9

    Vb 2008

    Apologies if this is a basic question but I am a newbie to VB. I have tried many searches but find it difficult to find a fitting answer.

    I am creating a VB 2008 project with SQL 2000 back end.

    I have a data source setup, table adapter etc and have populated a form with various fields from the dataset.

    I can add records to the DB no problem, however:

    What is the correct VB 2008 syntax to populate fields that are not on the form prior to saving the record.

    e.g. I have employee ID, First Name, Last Name etc whcih the user enters onto a windows form, but there is a field called hotel ID which the user should not need to populate as this is ascertained from the users login Id.

    I have sucessfully created a variable that holds this number @hotelno but don't know how to transfer this value to the SQL field. I wanted something like

    hotelno = (Employeesdatas et.Tables(1).Ro ws.Item(0).Item ("hotelid"))

    I know my syntax is all to cock, but hopefully you understand what I am trying to do.

    I think I am wrong in that I cannot address the dataset as this is a new record I am creating and therefore it doesn't exist in the dataset yet.

    Any help will be much appreciated
  • OuTCasT
    Contributor
    • Jan 2008
    • 374

    #2
    Code:
    Dim sqlConnection As SqlConnection
    sqlconnection = New sqlConnection("")
    
    'Commands and adapter for the Employee masterfile
        Dim sqlcommand As SqlCommand
        Dim sqlEmployeeAdapter As SqlDataAdapter
        Dim sqlEmployeeDataTable As DataTable
        Dim sqlManager as CurrencyManager
     
     sqlcommand = New SqlCommand("SELECT * FROM [table],sqlConnection)
            sqlEmployeeAdapter = New SqlDataAdapter(sqlcommand)
            sqlEmployeeDataTable = New DataTable
            sqlEmployeeAdapter.Fill(sqlEmployeeDataTable)
            ' Fill Table with EmployeeDetails
    txtEmployeeCode.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeID", True)
            txtSurname.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeSurname", True)
            txtInitials.DataBindings.Add("Text", sqlEmployeeDataTable, "EmployeeInitials", True)
            txtFirstNames.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeFirstName", True)
            cbTitle.DataBindings.Add("SelectedItem", sqlEmployeeDataTable, "EmployeeTitle", True)
            txtNickName.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeNickName", True)
    
    sqlEmployeeManager = DirectCast(Me.BindingContext(sqlEmployeeDataTable), CurrencyManager)
    like dat

    Comment

    • Dellboymash
      New Member
      • Feb 2008
      • 9

      #3
      Thanks for your quick response. I am leaving fior teh airport in an hour, so will look at it on my return

      Many thanks

      Comment

      • Dellboymash
        New Member
        • Feb 2008
        • 9

        #4
        I have looked at your response and am unable to work through it. I am not sure that it answers my question.

        All I want to know is what the syntax is for making a field in a dataset = a value.

        i.e.

        I have a dataset call employeesdatase t
        within the dataset is a table called employees
        within the table is a field called hotel

        I want to set the value of this field (within the current record the form is creating) to 41

        the other fields within the current record are bound to the form are are inputted by the user.

        The hotel field is not a field on the form but is held within the record.

        How to I make the field Hotel=41 before saving the record

        Hope this helps

        Comment

        Working...