189 8069 5689

vb.net定义键值对 C# 键值对

VB.net连接数据库创建新字段并对其进行赋值

首先打开数据源,然后使用alter table语句即可,具体范例如下:

专注于为中小企业提供成都网站建设、成都做网站服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业个旧免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了成百上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

Set cn = New ADODB.ConnectionSet rs = New ADODB.Recordsetconstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" 数据库路径及文件名 ""cn.Open constrDim str As Stringstr = "alter table 表名 add 字段 类型"rs.Open str, cn, adOpenStaticmsgbox"添加字段成功",vbokonly

vb.net 自建类生成类e似xx.item(0).value或者xx.Name("zhangshan").Value

'这是数组的一个方法了,可是可以给数组定义扩展方法来实现这种形式。不过要给Item每个成员能动态生成相应方法,想不出其它简单点的办法,只能一个一个的添加扩展方法。

Namespace 测试

Public Class Item

Public Number() As String

Public Name As String

Public Symbol As String

Public Value As Single

Public Unit As String

Public Description As String

Public Remarks As String

End Class

Public Class XX

Public tty() As Item

Public Sub New()

tty(0).Name = "Women"

tty(0).Value = 198000

tty(1).Name = "temen"

tty.Name("temen").Value = 99999

End Sub

End Class

Public Module Module1

System.Runtime.CompilerServices.Extension() _ 

Public Function Name(ByVal she As Item(), ByVal key As String) As Item '定义扩展方法功能 在net.3.5前的版本像似没有。

For Each it In she

If it.Name = key Then

Return it

End If

Next

Return Nothing

End Function

End Module

End Namespace

vb.net数据库操作

参考一下下面这段代码就可以了。

Imports System.Data

'引入数据库操作类命名空间

Imports System.Data.OleDb

'引入ADO.NET操作命名空间

Public Class FrmModifystInfo

Inherits System.Windows.Forms.Form

Public ADOcmd As OleDbDataAdapter

Public ds As DataSet = New DataSet()

'建立DataSet对象

Public mytable As Data.DataTable

'建立表单对象

Public myrow As Data.DataRow

'建立数据行对象

Public rownumber As Integer

'定义一个整型变量来存放当前行数

Public SearchSQL As String

Public cmd As OleDbCommandBuilder

'======================================================

#Region " Windows 窗体设计器生成的代码 "

#End Region

'======================================================

Private Sub FrmModifystInfo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

'窗体的载入

TxtSID.Enabled = False

TxtName.Enabled = False

ComboSex.Enabled = False

TxtBornDate.Enabled = False

TxtClassno.Enabled = False

TxtRuDate.Enabled = False

TxtTel.Enabled = False

TxtAddress.Enabled = False

TxtComment.Enabled = False '设置信息为只读

Dim tablename As String = "student_Info "

SearchSQL = "select * from student_Info "

ExecuteSQL(SearchSQL, tablename) '打开数据库

ShowData() '显示记录

End Sub

Private Sub ShowData()

'在窗口中的textbox中显示数据

myrow = mytable.Rows.Item(rownumber)

TxtSID.Text = myrow.Item(0).ToString

TxtName.Text = myrow.Item(1).ToString

ComboSex.Text = myrow.Item(2).ToString

TxtBornDate.Text = Format(myrow.Item(3), "yyyy-MM-dd ")

TxtClassno.Text = myrow.Item(4).ToString

TxtTel.Text = myrow.Item(5).ToString

TxtRuDate.Text = Format(CDate(myrow.Item(6)), "yyyy-MM-dd ")

TxtAddress.Text = myrow.Item(7).ToString

TxtComment.Text = myrow.Item(8).ToString

End Sub

Private Sub BtFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtFirst.Click

'指向第一条数据

rownumber = 0

ShowData()

End Sub

Private Sub BtPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtPrev.Click

'指向上一条数据

BtNext.Enabled = True

rownumber = rownumber - 1

If rownumber 0 Then

rownumber = 0 '如果到达记录的首部,行号设为零

BtPrev.Enabled = False

End If

ShowData()

End Sub

Private Sub BtNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtNext.Click

'指向上一条数据

BtPrev.Enabled = True

rownumber = rownumber + 1

If rownumber mytable.Rows.Count - 1 Then

rownumber = mytable.Rows.Count - 1 '判断是否到达最后一条数据

BtNext.Enabled = False

End If

ShowData()

End Sub

Private Sub BtLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtLast.Click

'指向最后一条数据

rownumber = mytable.Rows.Count - 1

ShowData()

End Sub

Private Sub BtDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtDelete.Click

mytable.Rows.Item(rownumber).Delete() '删除记录

If MsgBox( "确定要删除改记录吗? ", MsgBoxStyle.OKCancel + vbExclamation, "警告 ") = MsgBoxResult.OK Then

cmd = New OleDbCommandBuilder(ADOcmd)

'使用自动生成的SQL语句

ADOcmd.Update(ds, "student_Info ")

BtNext.PerformClick()

End If

End Sub

Private Sub BtModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtModify.Click

TxtSID.Enabled = False '关键字段只读

TxtName.Enabled = True '可读写

ComboSex.Enabled = True

TxtBornDate.Enabled = True

TxtClassno.Enabled = True

TxtRuDate.Enabled = True

TxtTel.Enabled = True

TxtAddress.Enabled = True

TxtComment.Enabled = True

End Sub

Private Sub BtUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtUpdate.Click

If Not Testtxt(TxtName.Text) Then

MsgBox( "请输入姓名! ", vbOKOnly + vbExclamation, "警告 ")

TxtName.Focus()

Exit Sub

End If

If Not Testtxt(ComboSex.Text) Then

MsgBox( "请选择性别! ", vbOKOnly + vbExclamation, "警告 ")

ComboSex.Focus()

Exit Sub

End If

If Not Testtxt(TxtClassno.Text) Then

MsgBox( "请选择班号! ", vbOKOnly + vbExclamation, "警告 ")

TxtClassno.Focus()

Exit Sub

End If

If Not Testtxt(TxtTel.Text) Then

MsgBox( "请输入联系电话! ", vbOKOnly + vbExclamation, "警告 ")

TxtTel.Focus()

Exit Sub

End If

If Not Testtxt(TxtAddress.Text) Then

MsgBox( "请输入家庭住址! ", vbOKOnly + vbExclamation, "警告 ")

TxtAddress.Focus()

Exit Sub

End If

If Not IsNumeric(Trim(TxtSID.Text)) Then

MsgBox( "请输入数字学号! ", vbOKOnly + vbExclamation, "警告 ")

Exit Sub

TxtSID.Focus()

End If

If Not IsDate(TxtBornDate.Text) Then

MsgBox( "出生时间应输入日期格式(yyyy-mm-dd)! ", vbOKOnly + vbExclamation, "警告 ")

Exit Sub

TxtBornDate.Focus()

End If

If Not IsDate(TxtRuDate.Text) Then

MsgBox( "入校时间应输入日期格式(yyyy-mm-dd)! ", vbOKOnly + vbExclamation, "警告 ")

TxtRuDate.Focus()

Exit Sub

End If

myrow.Item(0) = Trim(TxtSID.Text)

myrow.Item(1) = Trim(TxtName.Text)

myrow.Item(2) = Trim(ComboSex.Text)

myrow.Item(3) = Trim(TxtBornDate.Text)

myrow.Item(4) = Trim(TxtClassno.Text)

myrow.Item(5) = Trim(TxtTel.Text)

myrow.Item(6) = Trim(TxtRuDate.Text)

myrow.Item(7) = Trim(TxtAddress.Text)

myrow.Item(8) = Trim(TxtComment.Text)

mytable.GetChanges()

cmd = New OleDbCommandBuilder(ADOcmd)

'使用自动生成的SQL语句

ADOcmd.Update(ds, "student_Info ")

'对数据库进行更新

MsgBox( "修改学籍信息成功! ", vbOKOnly + vbExclamation, "警告 ")

TxtName.Enabled = False

ComboSex.Enabled = False

TxtBornDate.Enabled = False

TxtClassno.Enabled = False

TxtRuDate.Enabled = False

TxtTel.Enabled = False

TxtAddress.Enabled = False

TxtComment.Enabled = False '重新设置信息为只读

End Sub

Private Sub BtCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtCancel.Click

TxtSID.Enabled = False

TxtName.Enabled = False

ComboSex.Enabled = False

TxtBornDate.Enabled = False

TxtClassno.Enabled = False

TxtRuDate.Enabled = False

TxtTel.Enabled = False

TxtAddress.Enabled = False

TxtComment.Enabled = False

End Sub

Public Function ExecuteSQL(ByVal SQL As String, ByVal table As String)

Try

'建立ADODataSetCommand对象

'数据库查询函数

ADOcmd = New OleDbDataAdapter(SQL, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\student.mdb ")

'建立ADODataSetCommand对象

ADOcmd.Fill(ds, table) '取得表单

mytable = ds.Tables.Item(0) '取得名为table的表

rownumber = 0 '设置为第一行

myrow = mytable.Rows.Item(rownumber)

'取得第一行数据

Catch

MsgBox(Err.Description)

End Try

End Function

End Class

vb.net 数组的定义方法

1、点击VS工具。

2、打开后,新建一个Windows窗体应用程序。

3、新建完毕后,如图所示。

4、拖动一个按钮。

5、定义数组最常见的方法,如图示。

6、运行后,点击按钮,弹出提示正常。

7、定义数组第二种方法,属于动态的方法。

8、运行后,点击按钮,数组成功输出。

vb.net增加注册表键值

'你的错误:

'注册表中如果不存在子键"SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"

'你怎么能打开它呢?

'已帮你改好

Option Explicit On

Option Strict On

Module Program

Sub Main()

Dim key As Microsoft.Win32.RegistryKey=Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", True)

If key Is Nothing Then

key=Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION")

End If

Dim subkey As Microsoft.Win32.RegistryKey=key.CreateSubKey("2.exe")

subkey.SetValue("REG_DWORD", 111111, Microsoft.Win32.RegistryValueKind.DWord)

subkey.Close()

key.Close()

Console.Write("Press any key to continue . . . ")

Console.ReadKey(True)

End Sub

End Module

关于vb.net中属性的定义

Property用于标识一个类成员为属性而不是方法.属性可以被获取,属性在被获以的时候利用get句柄返回其值.属性可以被赋值,这个过程是由set句柄完成的.这两个句柄可以不同时存在.如果只有get而没有set,那属性就是只读的.如果只有set而没有get,那属性就是只写的.

就是定义了两个属性:s_name和s_sex

Overridable 表示这个属性可以被重载。


本文题目:vb.net定义键值对 C# 键值对
文章来源:http://cdxtjz.com/article/hicpdi.html

其他资讯