Imports System
Imports System.Data
Imports System.Data.SQL
Namespace myclass
Public Class Mdb
Private ConnStr As String
Public Sub New ( DBName As String)
ConnStr = "server=new\myserver; uid=sa; pwd=a; database=" &DBName
sqlstring = "select * from "
End Sub
'返回某一字段的顺序号(应用于DataSet对象,field为字段名)
Public Function Field_Id(dt as DataTable,field as string) as integer
for i=0 to dt.columns.count-1
if dt.columns(i).caption=field then
Field_Id=i
end if
next
end function
'传入表名及条件,传回DataSet对象
Public Function GetDataSet(table as string, SelectSQL as string) as DataTable
Dim Cmd as SQLDataSetCommand
Dim ds as DataSet=New DataSet()
Cmd=New SQLDataSetCommand(sqlstring &table &sql_string(SelectSQL), Connstr)
Cmd.FillDataSet(ds,table)
GetDataSet=ds.tables(table)
End Function
'查找符合条件的记录中某字段有多少种值,返回各种值的集合(如:现,银,记)
Public Function count_unsame_value(Table as string,selectSQL as string,field as string)as string
dim i as integer
dim dt as datatable=GetDataSet(table,selectsql)
dim n as integer=field_ID(dt,field)
dim str1,str2 as string
if dt.rows.count>0 then
str1=trim(dt.rows(0).item(n)).tostring
for i=1 to dt.rows.count-1
str2=trim(dt.rows(i).item(n)).tostring
if not instr(str1,str2) then
str1 &= "," &str2
end if
next
else
str1=""
end if
count_unsame_value=str1
End Function