Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi everyone
I have a app windows vb.net 2010 and sqlserver 2008 as a database
I have a form (for update data) that has two combobox one of them as selecting year and the other one as a selecting month (12 indexes ) and this form has a textbox and one button and one datagridview
my problem is that some of data update successfully but some of them not update successfully the problem is that there is no error when runing app
please help me thenks BEFOREHAND
this my code :

VB
Imports System.IO
Imports System.Data.SqlClient
Imports System.Text
Public Class sabt_tadieh
    Public cn As New SqlConnection("Data Source=FAZI-PC\EJRA_AHKAM;Initial Catalog=1;Persist Security Info=True;User ID=sa;Password=reza_132/132@")
       Public Sub tadieh_1()
        If ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (0) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 0).Value
        ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (1) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 1).Value
        ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (2) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 2).Value
        ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (3) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 3).Value
        ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (4) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 4).Value
        ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (5) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 5).Value
        ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (6) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 6).Value
        ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (7) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 7).Value
        ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (8) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 8).Value
        ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (9) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 9).Value
        ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (10) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 10).Value
        ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (11) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 11).Value
        ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (0) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 12).Value
        ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (1) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 13).Value
        ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (2) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 14).Value
        ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (3) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 15).Value
        ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (4) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 16).Value
        ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (5) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 17).Value
        ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (6) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 18).Value
        ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (7) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 19).Value
        ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (8) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 20).Value
        ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (9) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(4, 21).Value
        ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (10) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 22).Value
        ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (11) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 23).Value
        ElseIf ComboBoxEx1.SelectedIndex = (2) And ComboBoxEx2.SelectedIndex = (0) Then
            TextBoxX2.Text = ShakhesDataGridView.Item(2, 24).Value
              End If
    End Sub
' Public Sub tadieh_1  is  very long and CONTINUE to 348 indexes
    Public Sub display_data()
        cn.Open()
        Dim dt As New DataTable("shakhes")
        Dim rs As New SqlDataAdapter("select * from shakhes", cn)
        rs.Fill(dt)
        ShakhesDataGridView.DataSource = dt
        ShakhesDataGridView.Refresh()
        Label1.Text = dt.Rows.Count
        rs.Dispose()
        cn.Close()
        ShakhesDataGridView.Columns.Item(0).HeaderText = "سال تادیه"
        ShakhesDataGridView.Columns.Item(1).HeaderText = "ماه تادیه"
        ShakhesDataGridView.Columns.Item(2).HeaderText = "نرح شاخص "
    End Sub
    Public Sub Update_data()
        cn.Open()
        Dim rs As New SqlCommand("update shakhes set  tadieh_shakhes= '" & TextBoxX2.Text & "' where sal_tadieh='" & ComboBoxEx1.Text & "' and mah_tadieh='" & ComboBoxEx2.Text & "'", cn)
        rs.ExecuteNonQuery()
        cn.Close()
        display_data()
        TextBoxX2.Text = ""
        ComboBoxEx1.Text = ""
        ComboBoxEx2.Text = ""
        cn.Close()
    End Sub
    Private Sub sabt_tadieh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Ejra_dbDataSet.shakhes' table. You can move, or remove it, as needed.
        Me.ShakhesTableAdapter.Fill(Me.Ejra_dbDataSet.shakhes)
        expo()
        display_data()
    End Sub

    Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
        Update_data()
    End Sub

    Private Sub ComboBoxEx1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxEx1.SelectedIndexChanged
        tadieh_1()
    End Sub

    Private Sub ComboBoxEx2_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxEx2.SelectedIndexChanged
        tadieh_1()
    End Sub

    Private Sub ShakhesBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.ShakhesBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.Ejra_dbDataSet)

    End Sub
End Class
Posted
Updated 15-Aug-15 14:58pm
v5
Comments
[no name] 15-Aug-15 20:08pm    
Debug your code and find out what does not update and when. Then fix it.

1 solution

This code
VB
   Public Sub tadieh_1()
    If ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (0) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 0).Value
    ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (1) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 1).Value
    ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (2) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 2).Value
    ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (3) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 3).Value
    ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (4) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 4).Value
    ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (5) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 5).Value
    ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (6) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 6).Value
    ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (7) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 7).Value
    ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (8) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 8).Value
    ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (9) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 9).Value
    ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (10) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 10).Value
    ElseIf ComboBoxEx1.SelectedIndex = (0) And ComboBoxEx2.SelectedIndex = (11) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 11).Value
    ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (0) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 12).Value
    ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (1) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 13).Value
    ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (2) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 14).Value
    ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (3) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 15).Value
    ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (4) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 16).Value
    ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (5) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 17).Value
    ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (6) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 18).Value
    ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (7) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 19).Value
    ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (8) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 20).Value
    ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (9) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(4, 21).Value
    ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (10) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 22).Value
    ElseIf ComboBoxEx1.SelectedIndex = (1) And ComboBoxEx2.SelectedIndex = (11) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 23).Value
    ElseIf ComboBoxEx1.SelectedIndex = (2) And ComboBoxEx2.SelectedIndex = (0) Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, 24).Value
          End If
End Sub
can be simplified, and replaced by
VB
   Public Sub tadieh_1()
    Tmp= ComboBoxEx1.SelectedIndex * 12 + ComboBoxEx2.SelectedIndex
    If Tmp <= 24 Then
        TextBoxX2.Text = ShakhesDataGridView.Item(2, Tmp).Value
    End If
End Sub

Otherwise, try to understand when there is no update, and use the debugger to track you code and see what is wrong.
 
Share this answer
 
Comments
rezaeti 16-Aug-15 7:18am    
thanks

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



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