首页 新闻 会员 周边 捐助

vs2008中新建表格改变格式导入SQL2005数据库

0
悬赏园豆:5 [已关闭问题] 关闭于 2008-11-01 15:35

刚刚学用vs2008,在把数据添加到临时表格mtable中后,要改变格式插入到SQL2005数据库中,以下是代码:不知道哪里出了问题,就是不能导入SQL2005数据库        
            Dim mtable As DataTable = myDataset.Tables(0)
            Dim txt1 As String
            Dim i As Integer = 0
            Dim mrow As DataRow = mtable.NewRow
            If TextBox12.Text = "" Then TextBox11.Text = VB6.Format(Now, "yyyymm") & "0001"
            Try
                For Each mrow In mtable.Rows

                mrow = mtable.Rows(i)'————取得当前单元格的行
                   
            TextBox11.Text = VB6.Format(Now, "yyyymm") & VB6.Format(Microsoft.VisualBasic.Right((TextBox11.Text), 4) + 1, "0000")
            txt1 = "insert into ldtcb (ID,data,text1,text2,thr1,thr2,text3,text4,thr3,text5,thr4,cj2,sj2,cj3,sj3,cj4,sj4,sd) values ('" & TextBox11.Text & "','" _
                                          & mtable.Columns(9).ReadOnly & " ','" & Microsoft.VisualBasic.Left(mtable.Columns(0).ReadOnly, 3) & "','" & Microsoft.VisualBasic.Right(mtable.Columns(0).ReadOnly, 2) & "','" & mtable.Columns(1).ReadOnly & "','" & mtable.Columns(12).ReadOnly & "','" _
                                          & mtable.Columns(14).ReadOnly & "','" & mtable.Columns(13).ReadOnly & "','" & mtable.Columns(11).ReadOnly & "','" & mtable.Columns(15).ReadOnly & "','" & mtable.Columns(10).ReadOnly & "','" & mtable.Columns(3).ReadOnly & "','" _
                                          & mtable.Columns(4).ReadOnly & "','" & mtable.Columns(5).ReadOnly & "','" & mtable.Columns(6).ReadOnly & "','" & mtable.Columns(7).ReadOnly & "','" & mtable.Columns(8).ReadOnly & "','" & mtable.Columns(2).ReadOnly & "')"
                    InDelRecord(txt1)'执行插入

                    i = i + 1
                    Label21.Text = "正在导入……" & i / mtable.Rows.Count * 100 & "%"
                Next
                txt5 = "select * from ldtcb where wc like 0"
                txt4 = "select * from ldtcb where wc like 0 and cj3<>'' or cj4<>'' or sj4<>'' or sj3<>''"
                xbwsx()'执行刷新
                xbwqk()'执行变化
                MessageBox.Show("您的操作已经成功地执行!", "恭喜!", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Me.Cursor = Cursors.Default
                PictureBox1.Visible = False
                Label21.Visible = False
                Me.Enabled = True
            Catch
                Me.Enabled = True
                MessageBox.Show(Err.Description, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                Exit Sub
            End Try

问题补充: 自己解决了,刚才因为不了解vs2008的一个属性,所以产生了错误代码,下面是正确代码:谢谢大家 Dim mtable As DataTable = myDataset.Tables(0) Dim txt1 As String Dim i As Integer = 0 Dim mrow As DataRow = mtable.NewRow If TextBox12.Text = "" Then TextBox11.Text = VB6.Format(Now, "yyyymm") & "0001" Try For Each mrow In mtable.Rows TextBox11.Text = VB6.Format(Now, "yyyymm") & VB6.Format(Microsoft.VisualBasic.Right((TextBox11.Text), 4) + 1, "0000") txt1 = "insert into ldtcb (ID,data,text1,text2,thr1,thr2,text3,text4,thr3,text5,thr4,cj2,sj2,cj3,sj3,cj4,sj4,sd) values ('" & TextBox11.Text & "','" _ & mrow(mtable.Columns(9).ColumnName).ToString & " ','" & Microsoft.VisualBasic.Left(mrow(mtable.Columns(0).ColumnName), 3).ToString & "','" & Microsoft.VisualBasic.Right(mrow(mtable.Columns(0).ColumnName), 2).ToString & "','" & mrow(mtable.Columns(1).ColumnName).ToString & "','" & mrow(mtable.Columns(12).ColumnName).ToString & "','" _ & mrow(mtable.Columns(14).ColumnName).ToString & "','" & mrow(mtable.Columns(13).ColumnName).ToString & "','" & mrow(mtable.Columns(11).ColumnName).ToString & "','" & mrow(mtable.Columns(15).ColumnName).ToString & "','" & mrow(mtable.Columns(10).ColumnName).ToString & "','" & mrow(mtable.Columns(3).ColumnName).ToString & "','" _ & mrow(mtable.Columns(4).ColumnName).ToString & "','" & mrow(mtable.Columns(5).ColumnName).ToString & "','" & mrow(mtable.Columns(6).ColumnName).ToString & "','" & mrow(mtable.Colu
XBW的主页 XBW | 菜鸟二级 | 园豆:404
提问于:2008-11-01 14:38
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册