Write a data function in the DataGrid control

zhaozj2021-02-16  101

'********************************************************** *********************************************************** ********* "**************************************************************** **************************************** ******** '******** *********************************************************** *********************************************************** ** 'private subseatenewdatarow ()' Using the function manetamestable to generate table DIM getsqltable as datatable getsqltable = makeiteMTable ()

DIM selectsql = "select * from itmas"

'********************************************************** *********************************************************** ************************************* Get odbc mysql connection ***** ************************************************ *********************************************************** ********************************************* 'DIM MyConnection As New Odbconnection (mysqlconnect.connectionstring) DIM MyCommand As New Odbccommand (selectsql, myconnection) DIM CUSTDA AS ODBCDATAADAPTER = New ODBCDataAdapter (SELECTSQL, MyConnection)

MyConnection.Open () Dim MyReader As OdbcdataReader Dim Myupdate As OdbcdataAdapter

'********************************************************** *********************************************************** ********************************************************************************************************* ************************************************ *********************************************************** ******************************************* 'MyReader = mycommand.executeReader () while myreader.read ()' Add a record with the generated table DIM GetSqlrow as datroof getSqlrow = getSqlTable.newrow () 'Add record getSqlrow ("Material Code") = MyReader.GetValue (1) Getsqlrow ("Material Description) = MyReader.getValue (2) Getsqlrow ("Material Unit Price) = MyReader.GetValue (3) Getsqlrow (" Material Unit) = MyReader.getValue (4) Getsqlrow ("Security Inventory) = MyReader.getValue (6) getsqltable.Rows.Add (Getsqlrow) End while

'********************************************************** *********************************************************** ********************************* Close ODBC MySQL connection ***** ************************************************ *********************************************************** ******************************************* 'MyReader.close () MyConnection.Close ()

DIM DC AS Datacolumn for Each DC in getsqltable.columns console.writeline (dc.columnname) Next me.dateshow.datasource = getsqltable me.dateshow.readonly = true end SUB

'********************************************************** *********************************************************** ********* '************************************************************************** Main function ******************************************************* '********************************************************** *********************************************************** ********* 'private function makeitemTable () AS DATATABLE' Create a new table Dim ITEMTABLE AS DATATABLE = New DataTable ("") 'Add a list of columi DIM IDCOLUMN AS DATACOLUMN = New Datacolumn IDColumn.DataType = System.Type.gettype ("System.Int32") IDCOLUMN.COLUMNNAME = "Sequence" IDCOLUMN.AUTOINCREMENT = True ITEMTABLE.COLUMNS.ADD (IDCOLUMN)

Dim itemCodeColumn As DataColumn = New DataColumn itemCodeColumn.DataType = System.Type.GetType ( "System.String") itemCodeColumn.ColumnName = "Material code" itemCodeColumn.DefaultValue = "Fname" ItemTable.Columns.Add (itemCodeColumn)

Dim itemDescColumn As DataColumn = New DataColumn itemDescColumn.DataType = System.Type.GetType ( "System.String") itemDescColumn.ColumnName = "Material Description" ItemTable.Columns.Add (itemDescColumn)

Dim priceColumn As DataColumn = New DataColumn priceColumn.DataType = System.Type.GetType ( "System.String") priceColumn.ColumnName = "Materials Unit" ItemTable.Columns.Add (priceColumn)

Dim UnitColumn As Datacolumn = new Datacolumn UnitColumn.DataType = System.Type.GetType ("System.String") UnitColumn.columnname = "Material Unit" ITEMTABLE.COLUMNS.ADD (UnitColumn)

Dim safeBalColumn As DataColumn = New DataColumn safeBalColumn.DataType = System.Type.GetType ( "System.String") safeBalColumn.ColumnName = "safety stock" ItemTable.Columns.Add (safeBalColumn) 'Creating a keyword Dim keys (0) As DataColumn Keys (0) = IDCOLUMN ITEMTABLE.PRIMARYKEY = KEYS

'Return to just create a good table MakeTEMTABLE = ITEMTABLE END FUNCTION

转载请注明原文地址:https://www.9cbs.com/read-11000.html

New Post(0)