Click here to Skip to main content
15,042,397 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made a vb net app connecting to an sql database, I used binding navigator datagridview and biding source, I instead want to use toolbox buttons, textboxes and not bindigsource.

What I have tried:

this code works
VB.NET
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Reflection

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        
        Dim i As New Double
        SqlDataAdapter1.Fill(DataSet11, "Table_1")
       For index As Integer = 0 To DataGridView1.RowCount - 1
            i += Convert.ToDouble(Math.Round(DataGridView1.Rows(index).Cells(1).Value,2))
        Next
        TextBox1.Text = Convert.ToString(i)
        
        

    End Sub

    Private Sub BindingNavigator1_RefreshItems(sender As Object, e As EventArgs) Handles BindingNavigator1.RefreshItems
        Me.Table1BindingSource.EndEdit()
        '  Me.BindingContext(DataSet11, "Table_1").EndCurrentEdit()
        If DataSet11.HasChanges Then
            Try
                SqlDataAdapter1.Update(DataSet11, "Table_1")
                DataSet11.AcceptChanges()
            Catch eUpdate As System.Exception

                'Throw eUpdate
                MsgBox(eUpdate.Message.ToString)
            End Try
        End If
    End Sub

    Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
        Me.Table1BindingSource.CancelEdit()
        DataSet11.Table_1.RejectChanges()
    End Sub 

I want to use only dataset and sqldataadapter with textboxes and nor binding sources
I try and connect a textbox with out binding source text form1 list indexes but missing code for add new delete and navigations.
I tried this but no luck
VB
</pre Me.DataSet11.Table_1.First>


something like this
VB.NET
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.BindingContext.Item(DataSet11, "Table_1").AddNew()
        ' Me.DataSet11.Table_1.Last
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.SqlDataAdapter1.Fill(DataSet11, "Table_1")
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Me.BindingContext.Item(DataSet11, "Table_1").Position = Me.BindingContext.Item(DataSet11, "Table_1").Position + 1
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Me.BindingContext.Item(DataSet11, "Table_1").Position = Me.BindingContext.Item(DataSet11, "Table_1").Count - 1
    End Sub

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

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Me.BindingContext(DataSet11, "Table_1").EndCurrentEdit()
        If DataSet11.HasChanges Then
            Try
                SqlDataAdapter1.Update(DataSet11, "Table_1")
                DataSet11.AcceptChanges()
            Catch eUpdate As System.Exception

                'Throw eUpdate
                MsgBox(eUpdate.Message.ToString)
            End Try
        End If

    End Sub
End Class

I need the move fist delete and cancel code
Posted
Updated 24-Jul-21 3:39am
v3

1 solution

Remember the solution code in vb .net
VB.NET
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.BindingContext.Item(DataSet11, "Table_1").AddNew()
        ' Me.DataSet11.Table_1.Last
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.SqlDataAdapter1.Fill(DataSet11, "Table_1")
        

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Me.BindingContext.Item(DataSet11, "Table_1").Position = Me.BindingContext.Item(DataSet11, "Table_1").Position + 1
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Me.BindingContext.Item(DataSet11, "Table_1").Position = Me.BindingContext.Item(DataSet11, "Table_1").Count - 1
    End Sub

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

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Me.BindingContext(DataSet11, "Table_1").EndCurrentEdit()
        If DataSet11.HasChanges Then
            Try
                SqlDataAdapter1.Update(DataSet11, "Table_1")
                DataSet11.AcceptChanges()
            Catch eUpdate As System.Exception

                'Throw eUpdate
                MsgBox(eUpdate.Message.ToString)
            End Try
        End If

    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Me.BindingContext(DataSet11, "Table_1").RemoveAt(Me.BindingContext(DataSet11, "Table_1").Position)
    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        Me.BindingContext(DataSet11, "Table_1").CancelCurrentEdit()
    End Sub

    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        Me.BindingContext.Item(DataSet11, "Table_1").Position = Me.BindingContext(DataSet11, "Table_1").Position - Me.BindingContext(DataSet11, "Table_1").Count
    End Sub
End Class
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900