我定义了一个函数,如下:
public string[]GetGF(string str)
{
Qryzhanzhan="select Line_ID from Busline where Stop_Name ="+"'"+str+"'";
Qrycnn=new SqlConnection(this.Qryzhanzhanstr);
this.Qrycnn.Open();
SqlCommand cmd=new SqlCommand(Qryzhanzhan,Qrycnn);
SqlDataReader reader=cmd.ExecuteReader();
int o = 0;
string[] gf=new string[100];
while(reader.Read())
{
gf[o]=reader["Line_ID"].ToString(); o++;
}
this.Qrycnn.Close();
return gf;
}
我在按键里调用时:
string[] cf=new string[100];int g;
cf=GetGF(this.textBox2.Text.ToString().Trim());
这样应该把上面所有读取的字符串都放到cf中了吧?但是怎么读取cf的长度,函数只是返回这个字符串组,没有返回长度是多少?请高手帮忙一下
public string[]GetGF(string str)
{
Qryzhanzhan="select Line_ID from Busline where Stop_Name ="+"'"+str+"'";
Qrycnn=new SqlConnection(this.Qryzhanzhanstr);
this.Qrycnn.Open();
SqlCommand cmd=new SqlCommand(Qryzhanzhan,Qrycnn);
SqlDataReader reader=cmd.ExecuteReader();
int o = 0;
string[] gf=new string[100];
while(reader.Read())
{
gf[o]=reader["Line_ID"].ToString(); o++;
}
this.Qrycnn.Close();
return gf;
}
我在按键里调用时:
string[] cf=new string[100];int g;
cf=GetGF(this.textBox2.Text.ToString().Trim());
这样应该把上面所有读取的字符串都放到cf中了吧?但是怎么读取cf的长度,函数只是返回这个字符串组,没有返回长度是多少?请高手帮忙一下
解决方案 »
- 散分兼发布一个图像处理小工具:Crimm Imageshop 2.0
- foreach 语句不能作用于“System.Data.DataTable”类型的变量
- 我的电脑里,地址栏的下拉烈表框是怎么做的?
- 数据库的性能排名和极限记录数,有谁了解阿,能否给个列表
- 看看这段关机程序,在关机时出现错误???
- WEB服务,谁给我个简单例子,
- 我想做一个游戏外挂 怎么能找到那个游戏的窗口,并向这个窗口发送一些键盘指令
- 无法解压gzipstream
- 字符串与字节数组转换!!!
- dev grid的小问题。
- 怎么写一正则表达式验证由汉字编码成的UTF8字符
- 关于c#通信 传输文件 和networkstream问题 (我的毕设 请大家帮帮忙)
建议你使用ArrayListpublic string[]GetGF(string str)
{
Qryzhanzhan="select Line_ID from Busline where Stop_Name ="+"'"+str+"'";
Qrycnn=new SqlConnection(this.Qryzhanzhanstr);
this.Qrycnn.Open();
SqlCommand cmd=new SqlCommand(Qryzhanzhan,Qrycnn);
SqlDataReader reader=cmd.ExecuteReader();
int o = 0;
ArrayList gf=new ArrayList[100];
while(reader.Read())
{
gf.Add(reader["Line_ID"].ToString()); //把要的东西add进去,gf.Count会自动累加
}
this.Qrycnn.Close();
return gf;
}
ArrayList cf=GetGF(this.textBox2.Text.ToString().Trim());
cf.Count 就是你要的东西了。获取每一个得到字符串是:cf[i].ToString()或(string)cf[i]
exp: using System.Collections.Generic;
list<string> myStrList = new list<string>();
for(int i=0;i<10;i++)
{
myStrList.Add(i.tostring());
}
int i = myStrList.Count;
public List<string> GetGF(string str)
{
Qryzhanzhan="select Line_ID from Busline where Stop_Name ="+"'"+str+"'";
Qrycnn=new SqlConnection(this.Qryzhanzhanstr);
this.Qrycnn.Open();
SqlCommand cmd=new SqlCommand(Qryzhanzhan,Qrycnn);
SqlDataReader reader=cmd.ExecuteReader();
int o = 0;
List<string> gf=new List<string>();
while(reader.Read())
{
gf.Add(reader["Line_ID"].ToString()); //把要的东西add进去,gf.Count会自动累加
}
this.Qrycnn.Close();
return gf;
}
ArrayList cf=GetGF(this.textBox2.Text.ToString().Trim());
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
public List<string> GetVehicleList(string customerID)
{
string sqlStr;
SqlDataReader Reader;
List<string> vehicleList = new List<string>();
string currVehicle; DBCN = new SqlConnection(SqlConnectStr);
sqlStr = "select VehI_VehicleNO from Tab_VehicleInfo where VehI_CustomerID =" + customerID; try
{
DBCN.Open();
CMD = new SqlCommand();
CMD.CommandText = sqlStr;
CMD.Connection = DBCN;
CMD.CommandType = CommandType.Text; Reader = CMD.ExecuteReader();
CMD.Dispose();
while (Reader.Read())
{
currVehicle =SQLHelper.NotNull(Reader["VehI_VehicleNO"]);
vehicleList.Add(currVehicle);
}
}
finally
{
DBCN.Close();
}
return vehicleList; }
注意:此类在 .NET Framework 2.0 版中是新增的。
表示可通过索引访问的对象的强类型列表。提供用于对列表进行搜索、排序和操作的方法。 命名空间:System.Collections.Generic
程序集:mscorlib(在 mscorlib.dll 中)
改成 ArrayList gf=new ArrayList(); 就行了 然后取它的Count
using System.Collections;写上就行了。
int len = cf.Length;