问题描述
大家好
我有一个应用程序windows vb.net 2010和sqlserver 2008作为数据库
我有一个表单(用于更新数据)有两个组合框一个他们选择年份,另一个选择月份(12个索引)这个表格有一个文本框和一个按钮和一个数据网格
我的问题是一些数据更新成功,但其中一些没有成功更新问题是运行应用程序时没有错误
请帮助我BEFOREHAND
我的代码:
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 :
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
推荐答案
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
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.
这篇关于有关更新子的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!