学习型 ASP/PHP/ASP.NET 主机 30元/年全能 ASP/PHP/ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
发新话题
打印

VB.NET數據編程 急!!!!!!!

VB.NET數據編程 急!!!!!!!

VB.NET 中對數據庫編程真的好難嗎?
那位大蝦有這個方面的資料或是代碼可以分享一下嗎
多謝:

TOP

我刚学
不知道你在说什么
不过以我非常有限的知识觉得
VB.NET添加 修改  删除  数据很容易
以下代码直接复制既可用

dim strConnect as string
strConnect = "Provider=SQLOLEDB;User ID=sa;password=;database=数据库;server=服务器"

Private Sub Add()
        Try
            Dim conn3 As New OleDb.OleDbConnection(strConnect)
            Dim da1 As New OleDb.OleDbDataAdapter
            Dim com1 As New OleDb.OleDbCommand("insert AdminEmployee values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & cmb1.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "')", conn3)
             da1.InsertCommand = com1
            com1.Connection.Open()
            com1.ExecuteNonQuery()
            com1.Connection.Close()
            MsgBox("添加成功", MsgBoxStyle.Information)
        Catch ex As Exception
            MsgBox("Somethinsg worng " & ex.ToString)
        End Try
    End Sub
     '-------------------------------------------
    Private Sub Delete()
        Try
            Dim conn4 As New OleDb.OleDbConnection(strConnect)
            Dim da1 As New OleDb.OleDbDataAdapter
            Dim com2 As New OleDb.OleDbCommand("Delete From AdminEmployee where ID='" & TextBox1.Text & "'", conn4)
          da1.DeleteCommand = com2
            com2.Connection.Open()
            com2.ExecuteNonQuery()
            com2.Connection.Close()
            MsgBox("删除成功", MsgBoxStyle.Information)
        Catch ex As Exception
            MsgBox("Somethinsg worng " & ex.ToString)
        End Try
    End Sub
    '------------------------------------------------------------------------------------------------------------------------------------------
Private Sub Manage()
    Try
            Dim conn5 As New OleDb.OleDbConnection(strConnect)
            Dim da As New OleDb.OleDbDataAdapter
            Dim com3 As New OleDb.OleDbCommand("update AdminEmployee set Name ='" & TextBox2.Text & "',Address ='" & TextBox3.Text & "',Phone='" & TextBox4.Text & "',Email='" & TextBox5.Text & "',PostCard='" & TextBox6.Text & "',Position='" & cmb1.Text & "' where ID = '" & TextBox1.Text & "'", conn5)
           da.UpdateCommand = com3
            com3.Connection.Open()
            com3.ExecuteNonQuery()
            com3.Connection.Close()
            MsgBox("修改成功", MsgBoxStyle.Information)
        Catch ex As Exception
            MsgBox("系统发生错误,请确定操作正确!" & ex.ToString, MsgBoxStyle.Critical)
        End Try
    End Sub

[此贴子已经被作者于2005-1-19 12:11:33编辑过]


TOP

条件查询比较难哈!
21世纪什么最贵? 人才!

TOP

发新话题