VB.NETã§ãã¼ã¿ãã¼ã¹ã«æ¥ç¶ãã(ADO.NET)(1)
æè¡çãªã¡ã¢ãVB.NETã§ãã¼ã¿ãã¼ã¹ã«æ¥ç¶ããæ¹æ³ã¯ãè²ã
ãããã ãã©ãç¾å¨ã¯ADO.NETã使ã£ã¦æ¥ç¶ããã®ã主æµãããã
ãã¼ã¿ãã¼ã¹æ¥ç¶
æ¥ç¶ã¯ System.Data.SqlClient.SqlConnection ã¯ã©ã¹ã使ã£ã¦è¡ãã
ãã¼ã¿ãã¼ã¹æ¥ç¶ãµã³ãã«1
Dim Con As New System.Data.SqlClient.SqlConnection 'æ¥ç¶å æå® Con.ConnectionString = _ "Data Source = [ãµã¼ãå];" & _ "Initial Catalog = [ãã¼ã¿ãã¼ã¹å];" & _ "Integrated Security = SSPI" 'ãã¼ã¿ãã¼ã¹ããªã¼ãã³ Con.Open()
ãã¼ã¿ãã¼ã¹æ¥ç¶ãµã³ãã«2
Dim Con As System.Data.SqlClient.SqlConnection 'ã¤ã³ã¹ã¿ã³ã¹åæåæã«å¼æ°ã«æ¥ç¶æååãçªã£è¾¼ãã§ãè¯ã Con = New System.Data.SqlClient.SqlConnection _ ("Data Source = [ãµã¼ãå];" & _ "Initial Catalog = [ãã¼ã¿ãã¼ã¹å];" & _ "Integrated Security = SSPI") Con.Open()
ãã©ã³ã¶ã¯ã·ã§ã³ã®éå§
BeginTransaction()ã¡ã½ããã使ç¨ãã¦ãã©ã³ã¶ã¯ã·ã§ã³ãéå§ããã
ï¼ãã©ã³ã¶ã¯ã·ã§ã³ã®æ¦å¿µã«ã¤ãã¦ã¯SQLã®åéãªã®ã§å²æï¼
ãã©ã³ã¶ã¯ã·ã§ã³ãµã³ãã«
Dim Con As New System.Data.SqlClient.SqlConnection 'æ¥ç¶å æå® Con.ConnectionString = _ "Data Source = [ãµã¼ãå];" & _ "Initial Catalog = [ãã¼ã¿ãã¼ã¹å];" & _ "Integrated Security = SSPI" 'ãã¼ã¿ãã¼ã¹ããªã¼ãã³ Con.Open() 'ãã©ã³ã¶ã¯ã·ã§ã³ãéå§ Con.BeginTransaction()
ã¯ã¨ãªã¼çºè¡ã®æºå
çºè¡ãããã¯ã¨ãªã¼ã®è¨å®ã¯System.Data.SqlClient.SqlConnectionã¯ã©ã¹ã®CreateCommandã¡ã½ããã使ãæ¹æ³ã¨ãSystem.Data.SqlClient.SqlCommandã¯ã©ã¹ã使ãæ¹æ³ããããå é¨ã§ã¯ã©ã¡ãã«ããSqlClient.SqlConnectionã¯ã©ã¹ã使ã£ã¦ããã®ã§ã©ã¡ãã§ãæ§ããªãã
SqlClient.SqlConnectionã®CreateCommandã使ãå ´å
Dim Con As New System.Data.SqlClient.SqlConnection 'æ¥ç¶å æå® Con.ConnectionString = _ "Data Source = [ãµã¼ãå];" & _ "Initial Catalog = [ãã¼ã¿ãã¼ã¹å];" & _ "Integrated Security = SSPI" 'ãã¼ã¿ãã¼ã¹ããªã¼ãã³ Con.Open() 'ãã©ã³ã¶ã¯ã·ã§ã³ãéå§ Con.BeginTransaction() 'SQLã¯ã¨ãªã¼æãæ ¼ç´ãããå¤æ°commandã®ä½æ Dim command As System.Data.SqlClient.SqlCommand = Con.CreateCommand() 'å®è¡ããSQLã¯ã¨ãªã¼ãæå® command.CommandText = "SELECT * FROM [ãã¼ãã«å]" 'çµæãè¿ã£ã¦ããã¾ã§å¾ æ©ããç§æ° command.CommandTimeout = 15
SqlClient.SqlCommandã¯ã©ã¹ã使ãå ´å
Dim Con As New System.Data.SqlClient.SqlConnection 'æ¥ç¶å æå® Con.ConnectionString = _ "Data Source = [ãµã¼ãå];" & _ "Initial Catalog = [ãã¼ã¿ãã¼ã¹å];" & _ "Integrated Security = SSPI" 'ãã¼ã¿ãã¼ã¹ããªã¼ãã³ Con.Open() 'ãã©ã³ã¶ã¯ã·ã§ã³ãéå§ Con.BeginTransaction() 'SQLã¯ã¨ãªã¼æãæ ¼ç´ãããå¤æ°commandã®ä½æ Dim command As New System.Data.SqlClient.SqlCommand 'å ã»ã©ã¨éãã¯ã¨ãªã¼ã®éä¿¡å ãæå®ãã¦ãããªãã¨ãããªã command.Connection = Con 'å®è¡ããSQLã¯ã¨ãªã¼ãæå® command.CommandText = "SELECT * FROM [ãã¼ãã«å]" 'çµæãè¿ã£ã¦ããã¾ã§å¾ æ©ããç§æ° command.CommandTimeout = 15
両è ã¨ããã®æ®µéã§ã¯ã¾ã ã¯ã¨ãªã¼ã¯çºè¡ããã¦ããããExecuteãã¦ãããªãã¨å®éã«ã¯ã¨ãªã¼ã¯çºè¡ãããªãã
次åã«ç¶ãã
â»ãªãããããµã³ãã«ã³ã¼ãã¨ããã¡ããã¡ãééã£ã¦ããã ãã©ãè¨æ£ããæ°ãèµ·ãããªã