1、 .Net之数据库事务处理
一个函数:
PublicFunction OperateSQLWithTrans(ByVal strsql() AsString) AsInteger'事务方式执行数据库操作
Using conn As SqlClient.SqlConnection = New SqlClient.SqlConnection(My.Settings.shanhuaConnectionString + strConnString)
conn.Open()
Dim Trans As SqlClient.SqlTransaction = conn.BeginTransaction()
Dim i AsInteger
For i = 0 To strsql.Length - 1
Using comm As SqlClient.SqlCommand = New SqlClient.SqlCommand(strsql(i), conn)
comm.Transaction = Trans
comm.ExecuteNonQuery()
EndUsing
Next
Trans.Commit()
EndUsing
EndFunction
数据库连接打开之后定义一个事务,依次绑定Sqlcommand和该事务,并执行Sqlcommand.一般用于删除、插入、更新等操作!
2、 Bounds(边界)的用法
举例:在数据窗口中加入DateTimerPicker控件
动态声明一个DateTimerPicker控件
Dim dp As DateTimePicker = New DateTimePicker()
Load事件里面加下面语句——初始化格式
dp.CustomFormat = "yyyy-MM-dd"
dp.Format = DateTimePickerFormat.Custom
dp.Visible = False
dgv2.Controls.Add(dp)
Form中加入
Private Sub dgv2_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv2.CellEnter
If e.ColumnIndex = 10 Then
'改为想要的列
If dp Is Nothing Then
Return
End If
'Bounds为边界,类型为:System.Drawing.Rectangle。
'GetCellDisplayRectangle函数为获取数据窗口某单元格显示区域的矩形(True为仅返回单元格的显示部分,否则为整个单元格的界限)
dp.Bounds = dgv2.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True)
'设置日期控件的大小及位置
'显示日期控件
dp.Visible = True
Else
'隐藏日期控件
dp.Visible = False
End If
End Sub
注意:要代码实现DateTimerPicker控件的值与数据窗口的值的同步!
3、 文件夹改名
IO.Directory.Move(旧名, 新名)
4、 注册表操作
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ptfp.exe", "code", dgv(0, dgv.CurrentRow.Index).Value)
My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\航天信息\发票控管\路径", "", Nothing)