标题:Datagridview & textbox中内容插入到数据库
取消只看楼主
skwenl
Rank: 1
等 级:新手上路
帖 子:121
专家分:0
注 册:2007-10-23
结帖率:80%
 问题点数:0 回复次数:1 
Datagridview & textbox中内容插入到数据库
各位大虾,请问怎么将DataGridView中内容与若干个textbox中内容一起插入到sql 数据库某表中呢?

以下这些代码提示     "要定义为new实例" 搞不懂什么问题.....

 For x = 0 To row1 - 1
                    Gdata1 = Trim(DataGridView1.Rows(x).Cells(0).Value.ToString)
                    Gdata2 = Trim(DataGridView1.Rows(x).Cells(1).Value.ToString)
                    Gdata3 = Trim(DataGridView1.Rows(x).Cells(2).Value.ToString)
                    Gdata4 = Trim(DataGridView1.Rows(x).Cells(3).Value.ToString)
                    Gdata5 = Trim(DataGridView1.Rows(x).Cells(4).Value.ToString)
                    Gdata6 = Trim(DataGridView1.Rows(x).Cells(5).Value.ToString)
                    Gdata7 = Trim(DataGridView1.Rows(x).Cells(6).Value.ToString)
                    Gdata8 = Trim(DataGridView1.Rows(x).Cells(7).Value.ToString)
                    str1 = "insert into xhpsve(單號,編號,名稱,品牌,顔色,規格,單位,數量,金額,申請人編號,申請人姓名,部門,公司,作成日期,批准人編號,批准人姓名,批准日期,備註,批准人編號1,批准人姓名1,批准日期1,備註1,批准人編號2,批准人姓名2,批准日期2,備註2,文件狀況)values('" & Label20.Text & "','" & Gdata1 & "','" & Gdata2 & "','" & Gdata3 & "','" & Gdata4 & "','" & Gdata5 & "','" & Gdata6 & "','" & Gdata7 & "','" & Gdata8 & "','" & buse4 & "','" & buse3 & "','" & Label3.Text & "','" & buse2 & "','" & Label7.Text & "','" & bh1 & "','" & ComboBox1.Text & "','" & Label13.Text & "','" & TextBox1.Text & "','" & bh2 & "','" & ComboBox2.Text & "','" & Label11.Text & "','" & TextBox2.Text & "','" & bh3 & "','" & ComboBox3.Text & "','" & Label18.Text & "','" & TextBox3.Text & "','" & ComboBox4.Text & "') "
                    comm.Connection = conn
                     = CommandType.Text
                     = str1
                    Dim da1 As New SqlDataAdapter(str1, conn)
                    da1.SelectCommand = comm
                    da1.Fill(ds)
                Next
搜索更多相关主题的帖子: Datagridview 数据库 Value Cells ToString 
2008-08-15 09:59
skwenl
Rank: 1
等 级:新手上路
帖 子:121
专家分:0
注 册:2007-10-23
得分:0 
呵,找出原因了..

2008-08-15 11:13



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




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

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