我是这样写的 但是不行 帮忙看看怎么回事
public class .....
public mytable as datatable
........
myconnection.open()
dim mydataset as dataset
dim mydataadpater as oledataadapter("select * from biao",myconnection)
mydataadpater.fill(mydataset,"biao")
mytable.datasource = mydataset("biao")
在另一个窗口运行时 提示mytable no declare 请问怎么回事
我是这样写的 但是不行 帮忙看看怎么回事
public class .....
public mytable as datatable
........
myconnection.open()
dim mydataset as dataset
dim mydataadpater as oledataadapter("select * from biao",myconnection)
mydataadpater.fill(mydataset,"biao")
mytable.datasource = mydataset("biao")
在另一个窗口运行时 提示mytable no declare 请问怎么回事
你用这个Function试试
Private Function MakeNamesTable() As System.Data.DataTable
Dim namesTable As System.Data.DataTable = New System.Data.DataTable("Names")
Dim colum1 As DataColumn = New DataColumn
colum1.DataType = System.Type.GetType("System.String")
colum1.ColumnName = "列名1"
namesTable.Columns.Add(colum1)
Dim colum2 As DataColumn = New DataColumn
colum2.DataType = System.Type.GetType("System.String")
colum2.ColumnName = "列名2"
namesTable.Columns.Add(colum2)
......
MakeNamesTable = namesTable
End Function
'colum1为你要邦定到Table的第一个值colum2为你要邦定到Table的第2列的值
private sub addrow(byval colum1 as string,byval colum2 as string)
Dim myRow As DataRow
myRow = tb.NewRow()
myrow(0)=colum1.tosring '为上面定义的Table加入第一列赋值
myrow(1)=colum1.tostring '同上,第二列
tb.Rows.Add(myRow)
end sub
将tb定义在form2中,public tb as datatable
然后再form1_load里面加入
dim f2 as form2
f2.tb=MakeNamesTable() '就是程序初始化的时候就邦定设置好的表
上面的Function和Sub都是写在Form1中
这些定义完了后就用循环调用上面那个SUB,我只假设你数据库只有2列,所以只设了2个参数,你根据数据库的列自己可以在增加参数,当然Function中也要相应的增加对应的列,我设的参数是字符型,如果你有整形或则Double的话
在Function中 :System.Type.GetType("System.String")
改为System.Type.GetType("System.Int36") 或System.Type.GetType("System.Double")
完成之后,你在form2中加入:DataGridView1.DataSource = dt