ACSCars, Inc. Connected and Disconnected Environment
ACSCars, Inc.: Connected and Disconnected Environment
Refer to the ACSCars database from previous weeks and complete the following tasks and discussion.
•Using the connection created in the previous assignment, Discussion and the Data command, populate a DataGrid that connects to the Tcars table and shows all fields for the cars, including prices.
This is populated using addItem() method
import fl.controls.DataGrid;
var myDataGrid:DataGrid = new DataGrid();
myDataGrid.addColumn(“Tcars”);
myDataGrid.addColumn(“Tvendors”);
myDataGrid.addColumn(“Tdealers”);
myDataGrid.addColumn(“Transaction_master”);
myDataGrid.addItem({Tcars:”Car_id”, Tdealers:”dealer_id”, Tvendors:”vendor_id”, Transaction_master:”trans_id”});
myDataGrid.addItem({Tcars:”car_name”, Tdealers:”dealer_name”, Tvendors:”vendor_name”, Transaction_master:”dealer_id”});
myDataGrid.addItem({Tcars:”car_type”, Tdealers:”dealer_location”, Tvendors:”vendor_location”, Transaction_master:”car_id”});
myDataGrid.addItem({Tcars:”car_model”, Tdealers:”dealer_state”, Tvendors:”vendor_state”, Transaction_master:”car_amnt”});
myDataGrid.addItem({Tcars:”car_color”, Tdealers:”dealer_phno”, Tvendors:”vendor_phno”, Transaction_master:”car_discount”});
myDataGrid.addItem({Tcars:”car_price”, Tdealers:””, Tvendors:”vendor_items”, Transaction_master:”car_date”});
myDataGrid.width = 200; myDataGrid.move(10, 10);
addChild(myDataGrid);
Screen shot
•Bind the DataGrid to the DataReader in a connected environment.
SqlCommand cm = new SqlCommand(“Select * from ACSCars”, con);
SqlDataReader dr;
dr = cm.ExecuteReader();
DataTable dataTable = new DataTable();
dataTable.Load(dr);
•Answer the following questions with respect to a disconnected environment:
string ACSCarsConnectionString =
“Server=localhost;Database= ACSCars;” +
“Trusted_Connection=True;
MultipleActiveResultSets=True”;
◦How will the two DataAdapter objects be created?
The first step was creating a new Sqlconnection instance. This entailed including the System.Data.SqlClient namespace in the program.
After calling Open () on the sqlconnection created, we use another block for the sqldataAdapters
The third step entailed filling dataTable. The fill method was essential in populating the internal rows and columns on Datatable to match the SQL result
◦How will you retrieve data from these two DataAdapters?
Data is retrieved through “fill”. Fill is among the essential methods of retrieving data on the DataAdapter objects. Fill executes the query and fills the DatabAdapter objects with the results retrieved from the database.
◦What is the syntax for filling DataSet by using the Fill method?
The fill method allows users obtain the value of a column from the DataRow object and handles the casting DBNull. Basically, the fill method has six different prototypes.
When using the syntax, the table name that one passes is actually the source table name, so the actual table name as used in the Dataset may be different if table mapping is in use.
•In addition, define the steps involved in creating a database application by using DataAdapter Configuration Wizard.
The first step involves creating Windows Application template.
Step 2: Adding a Data Grid Control to the Form this stag einvolves adding Datagrid control to the form by dragging it from the Toolbox > Window forms category. Step 3: Adding a Data Adapter Componentthis is done by dragging sqlDataAdapter control from the Toolbox to the open form. When one drags the data adapter (Sql, OleDb, or ODBC), the DataAdapter configuration wizards open up.
The second page allows one crate a new connection or picking from the connection list. Note visual studio has default Puran SQL server.
Choosing a query type
This page is for selling command types. A command set entails SQL statement
Generate the SQL Statementthis page allows one build SQL statement.
Query Builder
This stage involves picking tables from the data source. This start by selecting ASCcars table to tead in the data. There are options of selecting as many tables as one may need.
Now, I’ll select three columns from the database table.
Step4: Setting and Reviewing Data Adapter properties once DataAdapter is on the form, one need to check the sqlDataAdapter component properties. This can be seen by right clicking on the adapter and selecting properties menu item.
Figure: Setting the SQL select command in the data adapter
Step 5: Filling the Data Grid Control with Datathis entails creating fillDbGrid, which fills a Dataset object. This is followed by reading data from a DataSet object and populating the DataGrid control.
Listing: FillDB Grid Methodprotected void FillDBGrid() { DataSet ds = new DataSet(); sqlDataAdapter1.Fill(ds); dataGrid1.DataSource = ds.DefaultViewManager; }Listing: Calling the Fill DB Grid from the Form1 constructorpublic Form1() { InitializeComponent(); FillDBGrid(); }
Leave a Reply
Want to join the discussion?Feel free to contribute!