MSFN Forum: Need Help with VB.NET - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Need Help with VB.NET Rate Topic: -----

#1 User is offline   notooth 

  • Junior
  • Pip
  • Group: Members
  • Posts: 53
  • Joined: 22-March 04

Posted 06 December 2004 - 07:15 PM

I am trying to add some new rows into an Access database using VB.NET at runtime, but the binding textboxes can not show off the new rows. They can only display the existing rows :} . Can anyone tell me how to show off the new rows? Here is the code:
   Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DataSet11.Clear()
        OleDbDataAdapter1.Fill(DataSet11, "Customers")
 
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.BindingContext(DataSet11, "Customers").Position = 0
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.BindingContext(DataSet11, "Customers").Position -= 1
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.BindingContext(DataSet11, "Customers").Position += 1
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.BindingContext(DataSet11, "Customers").Position = DataSet11.Customers.Count - 1
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Me.BindingContext(DataSet11, "Customers").EndCurrentEdit()
        OleDbDataAdapter1.Update(DataSet11, "Customers")
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Me.BindingContext(DataSet11, "Customers").AddNew()
    End Sub



#2 User is offline   codejunkie 

  • Member
  • PipPip
  • Group: Members
  • Posts: 172
  • Joined: 23-May 04

Posted 06 December 2004 - 08:10 PM

Eww.. Button1....Button5...Form3, HELLO, try naming stuff so u know what they are for and also use code for what they are in the name too
IE Button1 = btnAddRow
Form3 = frmNewRecord

It will make life a hole lot easier.
I will let you know as soon as I find my Old College project, I need it soon for my Win Tweak Compiler anyway.

PS don't worry your not the only one that strugges with added records in VB.NET the HOLE case did and that included the tutor :crazy: he was use to VB6 like me and not VB.NET, Never have tried linking VB6 to a database yet any how I will let you know asap

#3 User is offline   codejunkie 

  • Member
  • PipPip
  • Group: Members
  • Posts: 172
  • Joined: 23-May 04

Posted 08 December 2004 - 07:57 PM

I uses a Module to access my database, the code to add a user was

   Sub AnotherAddNewMemberAttempt(ByVal MembersName As String, ByVal UserName As String, ByVal Password As String, ByVal Position As String, ByVal Code As String, ByVal Access As String, ByVal Sport As String, ByVal Allowance As Integer)

        'addEmp.Parameters.Add("@LastName", SqlDbType.NVarChar, 20).Value = lastName
        'addEmp.Parameters.Add("@FirstName", SqlDbType.NVarChar, 10).Value = firstName

        Dim AddToMembers As Odbc.OdbcCommand = New Odbc.OdbcCommand("INSERT INTO ITP_MembersDetails (ITP_MemberDetails_Name,ITP_MemberDetails_UserName,ITP_MemberDetails_Password,ITP_MemberDetails_M
axSpending,ITP_MemberDetails_FavSport,ITP_MemberDetails_UserAccessType,ITP_MemberDetails_Position,IT
P_MemberDetails_Code)" &  "Values(@MembersName, @UserName, @Password, @Position, @Code, @UserAccessType, @FavSport, @MaxSpending)", formMain.OdbcConnection)

        AddToMembers.Parameters.Add("@MembersName", SqlDbType.NVarChar, 20).Value = MembersName
        AddToMembers.Parameters.Add("@UserName", SqlDbType.NVarChar, 20).Value = UserName
        AddToMembers.Parameters.Add("@Password", SqlDbType.NVarChar, 10).Value = Password
        AddToMembers.Parameters.Add("@Position", SqlDbType.NVarChar, 50).Value = Position
        AddToMembers.Parameters.Add("@Code", SqlDbType.NVarChar, 2).Value = Code
        AddToMembers.Parameters.Add("@UserAccessType", SqlDbType.NVarChar, 15).Value = Access
        AddToMembers.Parameters.Add("@FavSport", SqlDbType.NVarChar, 20).Value = Sport
        AddToMembers.Parameters.Add("@MaxSpending", SqlDbType.Int).Value = Allowance

        formMain.OdbcConnection.Open()

        Debug.WriteLine("SQL Commannd:")
        Debug.WriteLine(AddToMembers.CommandText)
        Debug.WriteLine("")
        Debug.WriteLine("Command Parameters:")
        Dim n As Integer
        Do Until n = AddToMembers.Parameters.Count
            Debug.WriteLine(AddToMembers.Parameters.Item(n))
            Debug.WriteLine(AddToMembers.Parameters.Item(n).Value)
            n += 1
        Loop


        MsgBox(AddToMembers.ExecuteNonQuery())

        formMain.OdbcConnection.Close()


    End Sub


I cant remmember if that worked, I used the code over a year and a half ago and the app was NEVER finished as it was good enought to get me my Merit on my level 3 course B) My web design was a destinction, WALK OVER! I Hate web Dev as its too easy to code, the problem is getting it to like goof :(

Ill have a look at your code and rewrite it


Like I said I didnt know if that code worked and it doesnt errors on the executeNonQuery

Heres some more code from MS website may help

[Visual Basic] 
Public Sub CreateMyOdbcCommand(myExecuteQuery As String, _
myConnectionString As String)
    Dim myConnection As New OdbcConnection(myConnectionString)
    Dim myCommand As New OdbcCommand(myExecuteQuery, myConnection)
    myCommand.Connection.Open()
    myCommand.ExecuteNonQuery()
    MyConnection.Close()
End Sub


Anyway I am going to bed...I mean sleep, Im already in bed :P well it is 2:49am here in the UK

This post has been edited by codejunkie: 08 December 2004 - 08:49 PM


#4 User is offline   codejunkie 

  • Member
  • PipPip
  • Group: Members
  • Posts: 172
  • Joined: 23-May 04

Posted 08 December 2004 - 08:54 PM

You need to genurate some SQL code to add the data and CLEAR the dataset!!! VERY IMPORTENT! and then fill it again, I will have to look at the code I have that works, I dont exactly know whats working, the code for checking your login details is spot on :P

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy