When the background database data bound to the DataGrid is displayed to the user, the negative number is changed to 0. Now it is recorded.
The data in this example indicates the following:
--------------------------------------------------------- Split line --------------------------------------
1. Call the DataGrid
DataGrid is a control that cannot be found in the vs toolbox for ASP. NET development. Therefore, you need to write code to call it:
Copy codeThe Code is as follows:
<Asp: DataGrid runat = "server" CssClass = "DataList" AutoGenerateColumns = "False" Id = "dgData"> </asp: DataGrid>
Note: AutoGenerateColumns indicates whether the DataGrid automatically generates columns. true indicates that columns are allowed to be generated, and false indicates that columns are not allowed.
If we choose not to allow this as in the example, we need to specify the column of the DataGrid, and the code will be extended:
Copy codeThe Code is as follows:
<Asp: DataGrid ID = "dgData" runat = "server" AutoGenerateColumns = "false">
<Columns>
<Asp: BoundColumn DataField = "LARGE" HeaderText = ""> </asp: BoundColumn>
<Asp: BoundColumn DataField = "smils" HeaderText = ""> </asp: BoundColumn>
</Columns>
</Asp: DataGrid>
The binding result will be:
If the column is automatically expanded, it is:
PS: What if we write this?
Copy codeThe Code is as follows:
<Asp: DataGrid ID = "dgData" runat = "server" AutoGenerateColumns = "true">
<Columns>
<Asp: BoundColumn DataField = "LARGE" HeaderText = ""> </asp: BoundColumn>
<Asp: BoundColumn DataField = "smils" HeaderText = ""> </asp: BoundColumn>
</Columns>
</Asp: DataGrid>
Select "true" for the attribute of the automatically expanded column, and I will add a Custom column to it. The result is
2. Connect to the database for operations
Copy codeThe Code is as follows:
OracleConnection conn = new OracleConnection ("Data Source = xxx; User Id = xxx; Password = xxx ;");
String sqlcmd = "select * from test_123 ";
Conn. Open ();
OracleCommand cmd = new OracleCommand (sqlcmd, conn );
DataSet dsRet = new DataSet ();
OracleDataAdapter ad = new OracleDataAdapter (cmd );
Ad. Fill (dsRet );
Conn. Close ();
Int I = dsRet. Tables [0]. Rows. Count;
Int j = dsRet. Tables [0]. Columns. Count;
For (int k = 0; k <I; k ++)
For (int m = 0; m <j; m ++)
{
If (int. Parse (dsRet. Tables [0]. Rows [k] [m]. ToString () <0)
DsRet. Tables [0]. Rows [k] [m] = "0 ";
}
DgData. DataSource = dsRet. Tables [0];
DgData. DataBind ();
First, the three axes of connecting to the database:
Create a Connection and query string, load Commond, and fill in DataAdapter.
I use DataSet as a large container. we can regard DataSet as a cabinet. There are many drawers in this cabinet. The drawer is a DataTable, and there is a grid in this drawer, what we put in the grid is the data we query, a grid is a number. The column and column coordinates are required to locate these numbers.
Generally, if you do not specify the drawer where the data table is stored, the system will default to 0th.
Because DataTable is a class, its instance is an object, and its content in this object is still an object, so you cannot think that the values stored in the DataTable look like int type, so my dsRet. tables [0]. Rows [k] [m] can be used as an integer and requires a conversion operation.
In this way, I can achieve what I originally wanted. It is very basic. Don't laugh. I also summarize it while learning, so that I can remember it.