Danh mục

Creating SQL Server Objects with ActiveX Data Objects

Số trang: 2      Loại file: pdf      Dung lượng: 8.84 KB      Lượt xem: 4      Lượt tải: 0    
Thu Hiền

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tạo SQL Server Đối tượng với ActiveX Data Objects Đó là giá trị phải đề cập đến một ví dụ của việc tạo ra một đối tượng bảng mới với các lĩnh vực và khóa chính quy định, mặc dù phần lớn các công việc của việc tạo ra các đối tượng sử dụng ADO và SQL Server được thực hiện trong T-SQL Báo cáo mà bạn tạo
Nội dung trích xuất từ tài liệu:
Creating SQL Server Objects with ActiveX Data Objects Creating SQL Server Objects with ActiveX Data ObjectsIt is worthwhile to mention an example of creating a new table object with fields andprimary key specified, even though the majority of the work of creating objects usingADO and SQL Server is done in the T-SQL Statement that you create. You will executethis statement using the Command object, as shown in Listing A.10.Listing A.10 basStoredProcedureExamples.vb: Creating SQL Server Objects withADO and T-SQLSub CreatingASQLServerObjectFromADO(ByVal txtResults As TextBox) Dim cnn As New ADODB.Connection() Dim cmd As New ADODB.Command() Dim prm As ADODB.Parameter Dim rstOld As New ADODB.Recordset() Dim rstNew As New ADODB.Recordset() -- In .NET, we can assign values as we declare variables. This is where the hard work is. Dim strSQL As String = CREATE TABLE Test (PrimaryIntFld Integer IDENTITY(1,1) PRIMARY KEY, Field2 Text) -- Open the connection OpenNorthwindADOConnection(cnn) -- Set up the Command object to use the SQL string. cmd.ActiveConnection = cnn cmd.CommandText = strSQL cmd.CommandType = ADODB.CommandTypeEnum.adCmdText -- Execute the command cmd.Execute()End SubThis routine is a lot like the previous example except for the SQL statement and the factthat results arent displayed. You can see the results by going to the Visual Studio .NETServer Explorer, zeroing in on the tables for the Northwind database, and opening thenew Test table in Design mode, as shown in Figure A.7. Figure A.7. Creating objects such as this table is just a matter of learning the correct SQL syntax.Note If you already had the tables displayed for Northwind, you might need to right-click on the Tables node and choose Refresh.

Tài liệu được xem nhiều: