自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

VB.NET數(shù)據(jù)庫實際范例解讀

開發(fā) 后端
對于剛剛接觸VB.NET編程語言不久的朋友來說,可能對于如何操作數(shù)據(jù)庫產(chǎn)生一定的疑問。我們就一起通過這篇文章來一起看看VB.NET數(shù)據(jù)庫的基本代碼實現(xiàn)。

如今的一個程序開發(fā)中基本上都需要對數(shù)據(jù)庫進行一定的操作,才能完成整個程序的完善性。在這里我們會了解到有關(guān)VB.NET數(shù)據(jù)庫的一些操作方面的代碼實現(xiàn),方便大家對這一方面的解讀。#t#

VB.NET數(shù)據(jù)庫代碼示例:

  1. Imports System  
  2. Imports System.Data  
  3. Imports System.Data.SqlClient  
  4. public Class MainClassclass MainClass  
  5. Shared Sub Main()Sub Main()  
  6. Dim thisConnection As New SqlConnection
    ("
    server=(local)\SQLEXPRESS;" & _  
  7. "integrated security=sspi;database=
    MyDatabase")  
  8. ' Sql Query   
  9. Dim sql As String = "SELECT * 
    FROM Employee "
     
  10. Dim insertSql As String = "INSERT
     INTO Employee "
     & _  
  11. "(ID, FirstName, LastName)VALUES" & _  
  12. "(@ID, @FirstName, @LastName)"  
  13. Try  
  14. ' Create Data Adapter  
  15. Dim da As New SqlDataAdapter  
  16. da.SelectCommand = New SqlCommand
    (sql, thisConnection)  
  17. ' Create and fill Dataset  
  18. Dim ds As New DataSet  
  19. da.Fill(ds, "Employee")  
  20. ' Get the Data Table  
  21. Dim dt As DataTable = ds.Tables
    ("Employee")  
  22. ' Display Rows Before Changed  
  23. Console.WriteLine("Before altering 
    the dataset")  
  24. For Each row As DataRow In dt.Rows  
  25. Console.WriteLine("{0} | {1} | {2}", _  
  26. row("ID").ToString().PadRight(10), _  
  27. row("FirstName").ToString().PadRight(10), _  
  28. row("LastName"))  
  29. Next  
  30. ' Add A Row  
  31. Dim newRow As DataRow = dt.NewRow()  
  32. newRow("FirstName") = "Edna"  
  33. newRow("LastName") = "Everage"  
  34. newRow("ID") = "2"  
  35. dt.Rows.Add(newRow)  
  36. ' Display Rows After Alteration  
  37. Console.WriteLine("=========")  
  38. Console.WriteLine("After 
    altering the dataset")  
  39. For Each row As DataRow In dt.Rows  
  40. Console.WriteLine("{0} | {1} | {2}", _  
  41. row("ID").ToString().PadRight(10), _  
  42. row("FirstName").ToString().PadRight(10), _  
  43. row("LastName"))  
  44. Next  
  45. ' Insert employees  
  46. ' 1. Create command  
  47. Dim insertCmd As New SqlCommand
    (insertSql, thisConnection)  
  48. ' 2. Map parameters  
  49. insertCmd.Parameters.Add("@FirstName", _  
  50. SqlDbType.NVarChar, 10, "FirstName")  
  51. insertCmd.Parameters.Add("@LastName", _  
  52. SqlDbType.NVarChar, 20, "LastName")  
  53. insertCmd.Parameters.Add("@ID", _  
  54. SqlDbType.Int, 15, "ID")  
  55. ' 3. Insert employees  
  56. da.InsertCommand = insertCmd 
  57. da.Update(ds, "Employee")  
  58. Catch ex As SqlException  
  59. ' Display error  
  60. Console.WriteLine("Error: " 
    & ex.ToString())  
  61. Finally  
  62. ' Close Connection  
  63. thisConnection.Close()  
  64. Console.WriteLine("Connection 
    Closed")  
  65. End Try  
  66. End Sub  
  67. End Class 

以上就是對VB.NET數(shù)據(jù)庫的應(yīng)用代碼示例進行的詳細解讀,希望對大家有所幫助。

責任編輯:曹凱 來源: 博客園
相關(guān)推薦

2010-01-13 15:01:13

VB.NET操作MyS

2010-01-18 14:47:42

VB.NET獲取環(huán)境變

2009-08-19 16:38:30

VB.NET接口范例

2010-01-18 17:37:32

VB.NET文本框處理

2009-10-28 17:08:57

VB.NET數(shù)據(jù)庫開發(fā)

2009-10-28 17:00:30

VB.NET數(shù)據(jù)庫

2009-10-13 17:31:50

VB.NET Acce

2010-01-12 10:40:58

VB.NET數(shù)據(jù)庫壓縮

2009-10-28 16:47:26

VB.NET訪問數(shù)據(jù)庫

2010-01-15 19:24:42

2009-10-09 15:20:26

VB.NET連接數(shù)據(jù)庫

2010-01-15 18:24:14

VB.NET打開Not

2010-01-13 09:31:39

VB.NET窗體打印

2009-10-28 17:24:19

VB.NET介紹

2010-01-18 19:21:51

VB.NET存取數(shù)據(jù)庫

2010-01-18 16:58:29

VB.NET Over

2010-01-14 09:55:06

VB.NET IEnu

2010-01-07 18:17:00

VB.NET連接SAP

2010-01-07 18:22:40

VB.NET聲音播放

2010-01-11 10:44:47

VB.NET多窗體
點贊
收藏

51CTO技術(shù)棧公眾號