notooth Posted December 7, 2004 Share Posted December 7, 2004 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 Link to comment Share on other sites More sharing options...
codejunkie Posted December 7, 2004 Share Posted December 7, 2004 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 tooIE Button1 = btnAddRowForm3 = frmNewRecordIt 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 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 Link to comment Share on other sites More sharing options...
codejunkie Posted December 9, 2004 Share Posted December 9, 2004 (edited) 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_MaxSpending,ITP_MemberDetails_FavSport,ITP_MemberDetails_UserAccessType,ITP_MemberDetails_Position,ITP_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 SubI 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 itLike I said I didnt know if that code worked and it doesnt errors on the executeNonQueryHeres 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 SubAnyway I am going to bed...I mean sleep, Im already in bed well it is 2:49am here in the UK Edited December 9, 2004 by codejunkie Link to comment Share on other sites More sharing options...
codejunkie Posted December 9, 2004 Share Posted December 9, 2004 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now