标题:球高人帮我看看这错在哪了。
取消只看楼主
lin7516
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-3-9
结帖率:100%
 问题点数:0 回复次数:0 
球高人帮我看看这错在哪了。
Imports System.Data.SqlClient
Imports System.Data
Public Class Form1
    Dim cn As SqlConnection
    Dim da As SqlDataAdapter
    Dim ds As DataSet
    Dim dt As DataTable
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            cn = New SqlConnection()
            cn.ConnectionString = "Data Source=XP-201311231519;Initial Catalog=小型数据库;Integrated Security=False;User ID=sa;Password=123456;"
            cn.Open()
            da = New SqlDataAdapter("select * from 加工量", cn)
            ds = New DataSet
            da.Fill(ds, "mytb1")
            Dim dr As DataRow
            dr = ds.Tables("mytb1").NewRow
            For i = 0 To DataGridView1.Rows.Count - 1
                dr("产品编码") = DataGridView1.Rows(i).Cells(1).Value
                dr("产品名称") = DataGridView1.Rows(i).Cells(2).Value
                dr("批次") = DataGridView1.Rows(i).Cells(3).Value
                ds.Tables("mytb1").Rows.Add(dr)
                Dim scb As New SqlCommandBuilder(da)
                da.Update(ds, "mytb1")
                DataGridView1.DataSource = ds.Tables("mytb1")
            Next
            cn.Close()
        Catch ex As Exception
        End Try
    End Sub
End Class
要不帮我看一下这个,为什么会有问题?就是dr("产品编码") = DataGridView1.Rows(i).Cells(1).Value
这句话,Rows(i)这个i用数字代替就可以用不出错,用变量就不行。求高人指点迷津。(代码是从书上抄的,源代码DataGridView1.Rows(i).Cells(1).Value这里是文本框)。
想要用DataGridView1批量更新数据库。
搜索更多相关主题的帖子: 数据库 False 
2014-03-12 10:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-428349-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021433 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved