菜鸟小弟接着昨天的问题继续请教各位朋友
小弟继续请教那个DATATABLE向数据库总提交问题系统(VS2003,语言是VB.NET,数据库是SQL2005EXPRESS)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
======================================================================================================
======================================================================================================
小弟附上该页面示意图,单位任务书居然规定我们在DATATABLE中放O和X以及文字,插入\更新\修改数据库的时候却要把这些非数字量转换成数字放到数据库里面
而且原先这个DATATABLE里面的数据是来自3个TABLE的,用VIEWSTATE传递整个DATATABLE,现在写回去只需写入一个TABLE,不知道是否是出错的原因
======================================================================================================
======================================================================================================
======================================================================================================
======================================================================================================
图里面,DATAGRID中的O和X,也就是DATATABLE中的O和X,对应着目标数据库中的1和0,要将这些O和X翻译成1和0插入目标数据库,难啊
菜鸟小弟苦不堪言,希望各位朋友帮助!!!!
在此感谢各位,等待SQL查询字符串的可用代码,谢谢!!!!
[:)]
--------------------编程问答-------------------- 先来做个沙发 --------------------编程问答-------------------- 把你这个看明白好像需要点时间~ --------------------编程问答-------------------- 我只剩下最后一块功能没做了,就是总提交按纽按下,将DATAGRID里面的数据源DATATABLE数据(按行循环)提交给数据库
[:)] --------------------编程问答-------------------- 谢谢送分,希望早日解决 --------------------编程问答-------------------- 哪里有图? --------------------编程问答-------------------- 把问题细分好不好,谁那么有空看完你这一大堆东西啊 --------------------编程问答-------------------- --------------------编程问答-------------------- 看得眼睛花了 --------------------编程问答-------------------- 这么长一段.... --------------------编程问答-------------------- 你是不是更新了TABLE的值,而改不了数据库中的值?
--------------------编程问答-------------------- 妈呀.有点乱! --------------------编程问答-------------------- 其实不是一般的乱,是相当乱。楼主你把问题细分下,细分到具体的小地方的时候估计你自己也搞明白了... --------------------编程问答--------------------
没看明白是啥东东....用VB写的...忘记的差不多了....继续学习.. --------------------编程问答--------------------
帮顶... --------------------编程问答-------------------- 好乱的东西.. --------------------编程问答-------------------- 是的,更新了TABLE的值,无法写回数据库 --------------------编程问答-------------------- 学习!
补充:.NET技术 , ASP.NET