1、vb.net ?完全符合面向?qū)ο蟮木幊陶Z(yǔ)言抽象、封裝、繼承的四大特性,而vb不支持繼承。
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名注冊(cè)、網(wǎng)頁(yè)空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、會(huì)昌網(wǎng)站維護(hù)、網(wǎng)站推廣。
2、錯(cuò)誤處理不同。
vb中只是On Error.....goto和On Errer Resume Next ,這些錯(cuò)誤稱為非結(jié)構(gòu)化異常處理。而在vb.net中采用的結(jié)構(gòu)化異常處理機(jī)制,try...catch....finally控制。
3、兩者產(chǎn)生的窗體不同。
vb.net 允許創(chuàng)建不同類型的應(yīng)用程序,例如,創(chuàng)建ASP.NET和ASP.NET Web 服務(wù)應(yīng)用程序,還允許創(chuàng)建控制臺(tái)應(yīng)用程序和作為桌面服務(wù)運(yùn)行的應(yīng)用程序。但是vb 只能創(chuàng)建Windows窗體。
4、數(shù)據(jù)庫(kù)訪問(wèn)的差別。
vb6.0是通過(guò)ADO(Active X Data Objext)來(lái)實(shí)現(xiàn)對(duì)數(shù)據(jù)庫(kù)訪問(wèn)。而vb.net 是通過(guò)ADO.NET來(lái)訪問(wèn)數(shù)據(jù)庫(kù)。
擴(kuò)展資料
Visual Basic(簡(jiǎn)稱VB)是Microsoft公司開(kāi)發(fā)的一種通用的基于對(duì)象的程序設(shè)計(jì)語(yǔ)言,為結(jié)構(gòu)化的、模塊化的、面向?qū)ο蟮摹瑓f(xié)助開(kāi)發(fā)環(huán)境的事件驅(qū)動(dòng)為機(jī)制的可視化程序設(shè)計(jì)語(yǔ)言。是一種可用于微軟自家產(chǎn)品開(kāi)發(fā)的語(yǔ)言。
“Visual” 指的是開(kāi)發(fā)圖形用戶界面 (GUI) 的方法——不需編寫(xiě)大量代碼去描述界面元素的外觀和位置,而只要把預(yù)先建立的對(duì)象add到屏幕上的一點(diǎn)即可。
“Basic”指的是 BASIC (Beginners All-Purpose Symbolic Instruction Code) 語(yǔ)言,是一種在計(jì)算技術(shù)發(fā)展歷史上應(yīng)用得最為廣泛的語(yǔ)言。
Visual Basic源自于BASIC編程語(yǔ)言。VB擁有圖形用戶界面(GUI)和快速應(yīng)用程序開(kāi)發(fā)(RAD)系統(tǒng),可以輕易的使用DAO、RDO、ADO連接數(shù)據(jù)庫(kù),或者輕松的創(chuàng)建Active?X控件,用于高效生成類型安全和面向?qū)ο蟮膽?yīng)用程序 。
參考資料:百度百科-Visual Basic
參考一下下面這段代碼就可以了。
Imports System.Data
'引入數(shù)據(jù)庫(kù)操作類命名空間
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對(duì)象
Public mytable As Data.DataTable
'建立表單對(duì)象
Public myrow As Data.DataRow
'建立數(shù)據(jù)行對(duì)象
Public rownumber As Integer
'定義一個(gè)整型變量來(lái)存放當(dāng)前行數(shù)
Public SearchSQL As String
Public cmd As OleDbCommandBuilder
'======================================================
#Region " Windows 窗體設(shè)計(jì)器生成的代碼 "
#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 '設(shè)置信息為只讀
Dim tablename As String = "student_Info "
SearchSQL = "select * from student_Info "
ExecuteSQL(SearchSQL, tablename) '打開(kāi)數(shù)據(jù)庫(kù)
ShowData() '顯示記錄
End Sub
Private Sub ShowData()
'在窗口中的textbox中顯示數(shù)據(jù)
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
'指向第一條數(shù)據(jù)
rownumber = 0
ShowData()
End Sub
Private Sub BtPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtPrev.Click
'指向上一條數(shù)據(jù)
BtNext.Enabled = True
rownumber = rownumber - 1
If rownumber 0 Then
rownumber = 0 '如果到達(dá)記錄的首部,行號(hào)設(shè)為零
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
'指向上一條數(shù)據(jù)
BtPrev.Enabled = True
rownumber = rownumber + 1
If rownumber mytable.Rows.Count - 1 Then
rownumber = mytable.Rows.Count - 1 '判斷是否到達(dá)最后一條數(shù)據(jù)
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
'指向最后一條數(shù)據(jù)
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( "確定要?jiǎng)h除改記錄嗎? ", MsgBoxStyle.OKCancel + vbExclamation, "警告 ") = MsgBoxResult.OK Then
cmd = New OleDbCommandBuilder(ADOcmd)
'使用自動(dòng)生成的SQL語(yǔ)句
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 '關(guān)鍵字段只讀
TxtName.Enabled = True '可讀寫(xiě)
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( "請(qǐng)輸入姓名! ", vbOKOnly + vbExclamation, "警告 ")
TxtName.Focus()
Exit Sub
End If
If Not Testtxt(ComboSex.Text) Then
MsgBox( "請(qǐng)選擇性別! ", vbOKOnly + vbExclamation, "警告 ")
ComboSex.Focus()
Exit Sub
End If
If Not Testtxt(TxtClassno.Text) Then
MsgBox( "請(qǐng)選擇班號(hào)! ", vbOKOnly + vbExclamation, "警告 ")
TxtClassno.Focus()
Exit Sub
End If
If Not Testtxt(TxtTel.Text) Then
MsgBox( "請(qǐng)輸入聯(lián)系電話! ", vbOKOnly + vbExclamation, "警告 ")
TxtTel.Focus()
Exit Sub
End If
If Not Testtxt(TxtAddress.Text) Then
MsgBox( "請(qǐng)輸入家庭住址! ", vbOKOnly + vbExclamation, "警告 ")
TxtAddress.Focus()
Exit Sub
End If
If Not IsNumeric(Trim(TxtSID.Text)) Then
MsgBox( "請(qǐng)輸入數(shù)字學(xué)號(hào)! ", vbOKOnly + vbExclamation, "警告 ")
Exit Sub
TxtSID.Focus()
End If
If Not IsDate(TxtBornDate.Text) Then
MsgBox( "出生時(shí)間應(yīng)輸入日期格式(yyyy-mm-dd)! ", vbOKOnly + vbExclamation, "警告 ")
Exit Sub
TxtBornDate.Focus()
End If
If Not IsDate(TxtRuDate.Text) Then
MsgBox( "入校時(shí)間應(yīng)輸入日期格式(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)
'使用自動(dòng)生成的SQL語(yǔ)句
ADOcmd.Update(ds, "student_Info ")
'對(duì)數(shù)據(jù)庫(kù)進(jìn)行更新
MsgBox( "修改學(xué)籍信息成功! ", 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 '重新設(shè)置信息為只讀
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對(duì)象
'數(shù)據(jù)庫(kù)查詢函數(shù)
ADOcmd = New OleDbDataAdapter(SQL, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\student.mdb ")
'建立ADODataSetCommand對(duì)象
ADOcmd.Fill(ds, table) '取得表單
mytable = ds.Tables.Item(0) '取得名為table的表
rownumber = 0 '設(shè)置為第一行
myrow = mytable.Rows.Item(rownumber)
'取得第一行數(shù)據(jù)
Catch
MsgBox(Err.Description)
End Try
End Function
End Class
如果樓主熟悉VB6,可以直接在項(xiàng)目中添加ADODB的Com引用,這樣你就可以像VB6那樣操作數(shù)據(jù)庫(kù)了!
另外
.NET
Framework中連接數(shù)據(jù)庫(kù)要用到ADO.NET。如果要操作Access數(shù)據(jù)庫(kù),要用到System.Data.OleDb命名空間下的許多類。
比如按樓主所說(shuō),“我想在textbox1中顯示表一中【一些數(shù)據(jù)】字段下的第一個(gè)內(nèi)容”:
'首先導(dǎo)入命名空間
Imports
System.Data
Imports
System.Data.OleDb
'然后在某一個(gè)事件處理程序中寫(xiě):
Dim
conn
As
New
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=數(shù)據(jù)庫(kù).accdb;Jet
OLEDB:Database
Password=MyDbPassword")
Dim
command
As
New
OleDbCommand("Select
*
From
數(shù)據(jù)表",
conn)
conn.Open()
'打開(kāi)數(shù)據(jù)庫(kù)連接
Dim
reader
As
OleDbDataReader
=
command.ExecuteReader()
'執(zhí)行SQL語(yǔ)句,返回OleDbDataReader
對(duì)象
Do
While
reader.Read()
'讀取一條數(shù)據(jù)
textbox1.Text
+=
reader("一些數(shù)據(jù)")
VbCrLf
Loop
reader.Close()
'關(guān)閉OleDbDataReader
conn.Close()
'關(guān)閉連接
1·綁定數(shù)據(jù)源來(lái)進(jìn)行連接
2.用代碼連接
先到數(shù)據(jù)庫(kù)建立一個(gè)數(shù)據(jù)庫(kù)和相應(yīng)的表
連接數(shù)據(jù)庫(kù)的代碼:
Dim str As String = "Data Source=服務(wù)器名;Initial Catalog=數(shù)據(jù)庫(kù)名;Persist Security Info=True;User ID=;Password="
dim conn As SqlClient.SqlConnection
try
conn = New SqlClient.SqlConnection
conn.ConnectionString = str
conn.Open()
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
登錄代碼:Dim str As String = "Data Source=服務(wù)器名;Initial Catalog=數(shù)據(jù)庫(kù)名;Persist Security Info=True;User ID=;Password="
dim conn As SqlClient.SqlConnection
conn = New SqlClient.SqlConnection
conn.ConnectionString = str
conn.Open()
sqlstr = "Select * From Amd Where AmdName='" TextBox1.Text "' And AmdPwd = '" TextBox2.Text "'"
Dim sqlcmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(sqlstr, conn)
Dim dr As SqlClient.SqlDataReader
dr = sqlcmd.ExecuteReader
If dr.Read = True Then '判斷一條記錄為真
kf.Show() '顯示下個(gè)窗體
Me.Hide() ’隱藏當(dāng)前窗體
Else
MessageBox.Show("輸入信息有誤!", "提示")
TextBox1.Text = ""
TextBox2.Text = ""
End If