vb.net导入excel,生成上级parent_id
2012-08-09 12:23
459 查看
tb_name = "tb_cat_department"
Dim depart_name As String = Nothing
Dim post_type As String = Nothing
Dim parent_id As Integer = 0
Dim tmp_id(1) As Integer
i = 0
For Each tmpdataRow In tmpDatatableX.Rows
i = i + 1
If i > 1 Then '导入数据从第2行开始
post_type = Convert.ToString(tmpdataRow(3))
For j = 0 To cols - 2
If Len(Convert.ToString(tmpdataRow(j))) > 0 Then
Dim rand = New System.Random()
Dim randx As String = rand.Next(100, 999).ToString() '随机数
depart_name = Convert.ToString(tmpdataRow(j))
Select Case j
Case 0 '第一列:部门
post_type = ""
parent_id = 0
Case 1 '第二列:岗位1
If Len(Convert.ToString(tmpdataRow(2))) > 0 Then
post_type = ""
End If
parent_id = tmp_id(0)
Case 2 '第二列:岗位2
parent_id = tmp_id(1)
Case Else
End Select
Sql_Str = "insert into [" + tb_name + "] " _
& "(depart_name,post_type,parent_id,import_date) " _
& " values ('" & depart_name & "','" & post_type & "'," & parent_id & ",'" & import_date + randx & "')"
TrueorFalse = ExecuteSqlstr(Sql_Str)
If TrueorFalse = True Then
wite_log("数据导入成功:" & depart_name & "','" & post_type & "'," & parent_id & ",'" & import_date + randx)
Sql_Str = "select id from [" + tb_name + "] where import_date='" & import_date + randx & "'"
If j = 0 Then
tmp_id(0) = getvaluestring(Sql_Str, "id")
End If
If j = 1 Then
tmp_id(1) = getvaluestring(Sql_Str, "id")
End If
Else
wite_log("数据导入失败:" & depart_name & "','" & post_type & "'," & parent_id & ",'" & import_date + randx)
End If
End If
Next
End If
Next
Dim depart_name As String = Nothing
Dim post_type As String = Nothing
Dim parent_id As Integer = 0
Dim tmp_id(1) As Integer
i = 0
For Each tmpdataRow In tmpDatatableX.Rows
i = i + 1
If i > 1 Then '导入数据从第2行开始
post_type = Convert.ToString(tmpdataRow(3))
For j = 0 To cols - 2
If Len(Convert.ToString(tmpdataRow(j))) > 0 Then
Dim rand = New System.Random()
Dim randx As String = rand.Next(100, 999).ToString() '随机数
depart_name = Convert.ToString(tmpdataRow(j))
Select Case j
Case 0 '第一列:部门
post_type = ""
parent_id = 0
Case 1 '第二列:岗位1
If Len(Convert.ToString(tmpdataRow(2))) > 0 Then
post_type = ""
End If
parent_id = tmp_id(0)
Case 2 '第二列:岗位2
parent_id = tmp_id(1)
Case Else
End Select
Sql_Str = "insert into [" + tb_name + "] " _
& "(depart_name,post_type,parent_id,import_date) " _
& " values ('" & depart_name & "','" & post_type & "'," & parent_id & ",'" & import_date + randx & "')"
TrueorFalse = ExecuteSqlstr(Sql_Str)
If TrueorFalse = True Then
wite_log("数据导入成功:" & depart_name & "','" & post_type & "'," & parent_id & ",'" & import_date + randx)
Sql_Str = "select id from [" + tb_name + "] where import_date='" & import_date + randx & "'"
If j = 0 Then
tmp_id(0) = getvaluestring(Sql_Str, "id")
End If
If j = 1 Then
tmp_id(1) = getvaluestring(Sql_Str, "id")
End If
Else
wite_log("数据导入失败:" & depart_name & "','" & post_type & "'," & parent_id & ",'" & import_date + randx)
End If
End If
Next
End If
Next
相关文章推荐
- [VB.NET]救命啊!!!数据库导入excel中的问题
- 使用vb将excel导入PowerDesigner,生成表结构2
- Excel导入导出,生成和下载Excel报表、附件等操作--ASP.NET
- VB.NET DataGridView中的数据导入到Excel
- Excel导入SQL(VB.NET版)
- VB.net 导入Excel方法(2010及以下版本适用)
- [VB.NET]vb.net里面怎么生成一个CSV文件,并把检索出来的数据集导入CSV
- Asp.net程序中用NPOI生成标准Excel报表,导入导出一应俱全[转]
- VB.NET 中生成Excel文件并弹出对话框保存
- VB .NET把Excel中的数据导入SQL SERVER数据库
- pd导入excel生成table的vb脚本。
- Asp.net程序中用NPOI生成标准Excel报表,导入导出一应俱全[转]
- Asp.net程序中用NPOI生成标准Excel报表,导入导出一应俱全
- [VB.NET]急.....使用OWC11导出Excel,怎么生成多个工作薄..
- 特别推荐:纯VB.NET代码直接生成Excel文件(不需要Excel)
- vb.net excel数据导入datagridview显示
- vb.net借助剪贴板将图片导入excel内
- VB.Net机房收费系统(三层)——将datagirdview 控件数据导入Excel
- sqlSever excel数据导入表中,表的ID格式化生成。
- [VB.NET]救助:将datagrid中的数据导入到excel中时遇到错误??