当前位置:编程学习 > C#/ASP.NET >>

小弟继续请教那个DATATABLE向数据库总提交问题,麻烦各位朋友帮助,谢谢!!

小弟继续请教那个DATATABLE向数据库总提交问题

系统(VS2003,语言是VB.NET,数据库是SQL2005EXPRESS) 

最麻烦的是DATAROW中保存的是"○"和"×",要翻译成"1"和"0"保存入数据库,麻烦死了
小弟昨天又通宵了,苦啊! --------------------编程问答-------------------- http://topic.csdn.net/u/20080414/01/17537ee5-c53c-432b-b6da-d5f32e05c536.html
还是上次这个帖子里的问题:) --------------------编程问答-------------------- 好象我无法把datatable里面的列值用 insert into 语句插入数据库table
datatable.Rows(i).Item(j)不就是datatable中第i行第j列吗,为什么不管用? --------------------编程问答-------------------- 麻烦各位帮助小弟,谢谢!![:)] --------------------编程问答-------------------- 你的那个报告什么错误啊?看看datatable.Rows(i).Item(j)里面的数据对没对应上? --------------------编程问答-------------------- 楼主把错误报靠贴出来让大家一起分析吧, --------------------编程问答--------------------

SQL语句修改如下:
===========================================================================================
  
'这些是待插入数据库的临时变量

        Dim Strdian_daima As String         '  
        Dim Strfuzeren_daimaAs String
        Dim Strdian_fenlei As String
        Dim Strxingneng_fenlei As String

        Dim Strshangban_Sun As String
        Dim Strshangban_Mon As String
        Dim Strshangban_Tue As String
        Dim Strshangban_Wed As String
        Dim Strshangban_Thu As String
        Dim Strshangban_Fri As String
        Dim Strshangban_Sat As String

        Dim StrDeleteFlag As String
        Dim StrEntryDate As String
        Dim StrEntryUser As String
        Dim StrUpdateDate As String
        Dim StrUpdateUser As String







'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
'以下是按纽事件代码,将DATAGRID中的DATATABLE写回到数据库的一部分-------插入DATAGRID中的新增记录 
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
For i = 0 To dt2.Rows.Count - 1            '遍历DATATABLE(dt2)中所有行,循环 
                    
                      If dt2.Rows(i).RowState = DataRowState.Added Then  '如果该行为新增, 
                                                                         '则将该行插入数据库,表名为Table1 
                     
'##########################################################################################################
                        '以下是为临时变量赋值,为将这些值插入数据库做准备
                        Strdian_daima = Trim(txtCode.Text) '店代码,取自页面标签
                        Strfuzeren_daima = strfuzeren      '负责人代码,取自公共变量 

                        If dt2.Rows(i).Item(1) = "DC" Then            '以下列值取自DATATABLE(dt2)
                            Strdian_fenlei = "1"
                        ElseIf dt2.Rows(i).Item(1) = "TC(商店)" Then
                            Strdian_fenlei= "2"
                        ElseIf dt2.Rows(i).Item(1) = "家庭" Then
                            Strdian_fenlei= "3"
                        ElseIf dt2.Rows(i).Item(1) = "超市" Then
                           Strdian_fenlei= "4"
                        End If

                        If dt2.Rows(i).Item(2) = "普通" Then
                            Strxingneng_fenlei  = "1"
                        ElseIf dt2.Rows(i).Item(2) = "特殊" Then
                            Strxingneng_fenlei = "2"
                        ElseIf dt2.Rows(i).Item(2) = "特别" Then
                            Strxingneng_fenlei = "3"
                        End If

                        If dt2.Rows(i).Item(3) = "○" Then
                            Strshangban_Sun = "1"
                        ElseIf dt2.Rows(i).Item(3) = "×" Then
                            Strshangban_Sun = "0"
                        End If


                        If dt2.Rows(i).Item(4) = "○" Then
                            Strshangban_Mon = "1"
                        ElseIf dt2.Rows(i).Item(4) = "×" Then
                            Strshangban_Mon = "0"
                        End If

                        If dt2.Rows(i).Item(5) = "○" Then
                            Strshangban Tue = "1"
                        ElseIf dt2.Rows(i).Item(5) = "×" Then
                            Strshangban_Tue = "0"
                        End If

                        If dt2.Rows(i).Item(6) = "○" Then
                            Strshangban_Wed = "1"
                        ElseIf dt2.Rows(i).Item(6) = "×" Then
                            Strshangban_Wed = "0"
                        End If


                        If dt2.Rows(i).Item(7) = "○" Then
                            Strshangban_Thu = "1"
                        ElseIf dt2.Rows(i).Item(7) = "×" Then
                            Strshangban_Thu = "0"
                        End If


                        If dt2.Rows(i).Item(8) = "○" Then
                            Strshangban_Fri = "1"
                        ElseIf dt2.Rows(i).Item(8) = "×" Then
                            Strshangban_Fri = "0"
                        End If


                        If dt2.Rows(i).Item(9) = "○" Then
                            Strshangban_Sat = "1"
                        ElseIf dt2.Rows(i).Item(9) = "×" Then
                            Strshangban_Sat = "0"
                        End If
                                                  '以下列值不是取自DATATABLE
                        StrDeleteFlag = "0"              
                        StrEntryDate = Format(date1, "yyyy/MM/dd HH:mm:ss")
                        StrEntryUser = strUserId
                        StrUpdateDate = Format(date1, "yyyy/MM/dd HH:mm:ss")
                        StrUpdateUser = strUserId

                    
                        strSql = strSql & "INSERT INTO Table1" 
                        strSql = strSql & " ("
                        strSql = strSql & " dian_daima,"
                        strSql = strSql & " fuzeren_daima,"
                        strSql = strSql & " dian_fenlei,"
                        strSql = strSql & " xingneng_fenlei,"
                        strSql = strSql & " shangban_Sun,"
                        strSql = strSql & " shangban_Mon,"
                        strSql = strSql & " shangban_Tue,"
                        strSql = strSql & " shangban_Wed,"
                        strSql = strSql & " shangban_Thu,"
                        strSql = strSql & " shangban_Fri,"
                        strSql = strSql & " shangban_Sat,"

                        strSql = strSql & " DeleteFlag,"
                        strSql = strSql & " EntryDate,"
                        strSql = strSql & " EntryUser,"
                        strSql = strSql & " UpdateDate,"
                        strSql = strSql & " UpdateUser )"

                      
                        strSql = strSql & " VALUES ('" & Strdian_daima & "','" & Str fuzeren_daima & "','" & Strdian_fenlei,& "','" & 

Strxingneng_fenlei & "','" & Strshangban _Sun & "','" & Strshangban _Mon & "','" & Strshangban _Tue & "','" & Strshangban _Wed & "','" & 

Strshangban _Thu & "','" & Strshangban _Fri & "','" & Strshangban _Sat & "','" & StrDeleteFlag & "','" & StrEntryDate & "','" & StrEntryUser & 

"','" & StrUpdateDate & "','" & StrUpdateUser & "')"     '以上是根据DATAGRID上的显示值来匹配相应单位数值,插入数据库 
                         
                      End If
Next --------------------编程问答-------------------- 为什么这样的语句还是不行,小弟郁闷了:( --------------------编程问答-------------------- 把那个X和O当成字符串插入到字段中,字段的类型也设置为varchar类型,这样试试应该可以了 --------------------编程问答--------------------
引用 8 楼 wh110 的回复:
把那个X和O当成字符串插入到字段中,字段的类型也设置为varchar类型,这样试试应该可以了

麻烦帮我示范下看看,小弟太菜了:(
谢谢:) --------------------编程问答-------------------- 请问如何把X和O当成字符串插入到字段中?
还有把字段的类型也设置为varchar类型?
请问如何做,小弟等待代码,谢谢!!
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,