« Home « Chủ đề sybex - c.sharp database programming

Chủ đề : sybex - c.sharp database programming


Có 40+ tài liệu thuộc chủ đề "sybex - c.sharp database programming"

Creating a Sqldatareader Objec

tailieu.vn

Creating a SqlDataReader Object. You can create a DataReader object only by calling the ExecuteReader() method of a Command object. Command objects were covered in the previous chapter. For example, the following code creates the required objects and executes a SELECT statement that retrieves the top five rows from the Products table of the SQL Server Northwind database, storing the...

Creating a Table

tailieu.vn

You can use Enterprise Manager to add a table to a database. In this section, you'll add a table to the Northwind database to store the details of a person. This table will be called Persons, and will contain the columns shown in Table 2.8.. Table 2.8: DEFINITION FOR THE COLUMNS OF THE Persons TABLE COLUMN NAME DATABASE TYPE LENGTH...

Creating a UniqueConstraint Object

tailieu.vn

foreach (DataColumn myDataColumn in myUC.Columns). Console.WriteLine("myUC.ConstraintName = ". myUC.ConstraintName);. Console.WriteLine("myUC.IsPrimaryKey = ". myUC.IsPrimaryKey);. Console.WriteLine("myUC.Table = ". myUC.Table);. myUC.ConstraintName = UniqueConstraintCustomerID myUC.IsPrimaryKey = True. myUC.Table = Customers

Creating and Using a DataRelation Object

tailieu.vn

In this section, you'll learn how to create a DataRelation object to define a relationship between two DataTable objects that hold some rows from the Customers and Orders tables. As you know, the CustomerID column of the child Orders table is a foreign key that links to the CustomerID column of the parent Customers table.. Once you've created a DataRelation,...

Creating and Using a DataView Object

tailieu.vn

myDataTable specifies the DataTable that your DataView is associated with. Your DataView will read the rows from this DataTable. The Table property of your DataView is set to myDataTable.. filterExpression specifies a string containing the expression you want to filter the rows by. The RowFilter property of your DataView is set to filterExpression.. sortExpression specifies a string containing the expression...

Creating and Using a DataViewManager Object

tailieu.vn

myDVM.DataViewSettings["Customers"].Sort = "CustomerID";. myDVM.DataViewSettings["Customers"].RowFilter = "Country = 'UK'";. DataView customersDV = myDVM.CreateDataView(customersDT);. set the Sort and RowFilter properties for the Customers DataTable myDVM.DataViewSettings["Customers"].Sort = "CustomerID";. display the DataViewSettingCollectionString property of myDVM Console.WriteLine("myDVM.DataViewSettingCollectionString = ". myDVM.DataViewSettingCollectionString + "\n");. myDVM.DataViewSettingCollectionString = <DataViewSettingCollectionString>

Creating Child DataView Objects

tailieu.vn

Creating Child DataView Objects. You can create a child DataView from a parent DataRowView using the. CreateChildView() method. You can then view the DataRowView objects from the child DataView. To call the CreateChildView() method, you must first add a DataRelation to the DataSet that defines a relationship between the two underlying DataTable objects.. Assume you have two DataTable objects named....

Creating User-Defined Functions

tailieu.vn

You can create your own user-defined functions in SQL Server. You create a function using the CREATE. Inline table-valued functions Inline table-valued functions return an object of the table type. You can think of a table as a regular database table, except it is stored in memory. An inline table-valued function can return the results retrieved by only a single...

Dealing with Update Failures

tailieu.vn

So far, the examples you've seen have assumed that the updates pushed to the database by the Update() have succeeded. Note You'll find all the code examples shown in this section in the. HandlingUpdateFailures.cs file located in the ch11 directory. In the examples in this section, assume that the CommandText property of a SqlDataAdapter object's UpdateCommand is set as follows:....

Defining a Relationship Using Visual Studio .NET

tailieu.vn

These DataTable objects will reference the Customers and Orders database tables. You'll then learn how to define a relationship between the two DataTable objects in the XML schema.. Enter the name of the project as DataRelation, as shown in Figure 12.2.. Figure 12.2: Creating the Windows application 2. Open Server Explorer and connect to the Northwind database using the connection...

Developing a Simple Windows Application phần 1

tailieu.vn

In this section, you'll see how to create a simple Windows application using VS .NET.. You'll also see how to compile and run the example application.. Start VS .NET by selecting Start ➣ Programs ➣ Microsoft Visual Studio .NET ➣ Microsoft Visual Studio .NET. Tip You can also create a new project by pressing Ctrl+Shift+N on your keyboard.. You'll see...

Developing a Simple Windows Application phần 2

tailieu.vn

this.myLabel = new System.Windows.Forms.Label();. this.myButton = new System.Windows.Forms.Button();. this.SuspendLayout();. this.myLabel.Location = new System.Drawing.Point(8, 8);. this.myLabel.Name = "myLabel";. this.myLabel.Size = new System.Drawing.Size(288, 184);. this.myLabel.TabIndex = 0;. this.myLabel.Text = "label1";. this.myButton.Location = new System.Drawing.Point(120, 200);. this.myButton.Name = "myButton";. this.myButton.Size = new System.Drawing.Size(72, 24);. this.myButton.TabIndex = 1;. this.myButton.Text = "Press Me!";. this.myButton.Click. new System.EventHandler(this.myButton_Click);. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);. this.ClientSize = new System.Drawing.Size(304,...

Developing Your First ADO.NET

tailieu.vn

In this section you'll plunge into ADO.NET programming and see a C# program that performs the following tasks:. Connects to the SQL Server Northwind database 2. Retrieves a row from the Customers table. Closes the database connection. You'll be introduced to many concepts in this section that are fully explored in later chapters. Don't be too concerned about all the...

Developing Your First ADO.NET phần 2

tailieu.vn

Step 3: Set the CommandText Property of the SqlCommand Object. Step 3 sets the CommandText property of mySqlCommand created in the previous step to a SELECT statement. This statement will retrieve the CustomerID, CompanyName, ContactName, and Address columns from the row in the Customers table whose CustomerID is ALFKI:. Step 4 opens the database connection using the Open() method of...

Executing Commands that Modify Information in the Database

tailieu.vn

You can use the ExecuteNonQuery() method of a Command object to execute any command that doesn't return a result set from the database. In this section, you'll learn how to use the ExecuteNonQuery() method to execute commands that modify. You can use the ExecuteNonQuery() method to execute SQL INSERT, UPDATE, and DELETE statements. You can also use the ExecuteNonQuery() method...

Executing Multiple SQL Statements

tailieu.vn

Executing Multiple SQL Statements. That's a lot of network traffic! One way to potentially reduce network traffic is to execute multiple SQL statements at a time.. In this section, you'll see how to execute multiple SELECT statements and retrieve results, and you'll see how to execute multiple SELECT, INSERT, UPDATE, and DELETE statements that are interleaved.. Executing Multiple SELECT Statements....

Executing SELECT Statements and TableDirect Commands phần 1

tailieu.vn

A Command object has three methods you can use to execute a SELECT statement or TableDirect command. Table 8.4 shows these methods, which you'll learn how to use in the following sections.. Table 8.4: METHODS THAT RETRIEVE INFORMATION FROM THE DATABASE. Applies only to the SqlCommand class.. Executing a SELECT Statement Using the ExecuteReader() Method Let's take a look at...

Executing SELECT Statements and TableDirect Commands phần 2

tailieu.vn

Listing 8.3: SCHEMAONLYCOMMANDBEHAVIOR.CS. SchemaOnlyCommandBehavior.cs illustrates how to read a table schema. using System.Data;. using System.Data.SqlClient;. mySqlCommand.CommandText. "WHERE ProductID = 1";. display the rows and columns in the DataTable. ((System.Data.SqlDbType) myDataRow[myDataColumn]));. You should notice the different details for the ProductID, ProductName, and UnitPrice columns in the output that follows:. DataType = System.Int32 AllowDBNull = False ProviderType = 8 ProviderType = Int...

Executing SQL Server Stored Procedures phần 1

tailieu.vn

Executing SQL Server Stored Procedures. You execute a stored procedure using the T-SQL EXECUTE statement. Although you can use this CommandType to indicate that a command is to execute a stored procedure, you're actually better off using the T-SQL EXECUTE command to execute a stored procedure. This is because you can read values that are returned from a stored procedure...

Executing SQL Server Stored Procedures phần 2

tailieu.vn

except that it uses a RETURN statement instead of an OUTPUT parameter to return the ProductID for the new row. Listing 8.13: ADDPRODUCT2.SQL. AddProduct2.sql creates a procedure that adds a row to the Products table using values passed as parameters to the. The procedure returns the ProductID of the new row using a RETURN statement. so SCOPE_IDENTITY returns the ProductID...