日期:2014-05-17  浏览次数:20911 次

DataSet中怎么截取表里的字符
要把 car_fee_hostname 字段的头两个字符显示 比如:“二楼收费亭—入场”、“负二停车场—出场”就显示为:“二楼”、“负二”

现在这样写的话
C# code
string place_class_sql = "select DISTINCT stringsub(car_fee_hostname,1,2) FROM car_park_fee where car_fee_flag = 2";现在报错"dl_fee_place.DisplayMember = "car_fee_hostname";"  
报错
C# code

string place_class_sql = "select DISTINCT car_fee_hostname FROM car_park_fee where car_fee_flag = 2";
SqlConnection place_conn = new SqlConnection(fee_conn.sql_conn());
DataSet complace = new DataSet();
place_conn.Open();
SqlDataAdapter myplace = new SqlDataAdapter(place_class_sql, class_conn);
myplace.Fill(complace, "ds");
place_conn.Close();
DataRow dw = complace.Tables[0].NewRow();
dw["car_fee_hostname"] = "全部收费口";
complace.Tables[0].Rows.InsertAt(dw,0);
dl_fee_place.DisplayMember = "car_fee_hostname";
this.dl_fee_place.DataSource = complace.Tables[0];
dl_fee_place.SelectedIndex = 0;



------解决方案--------------------
select DISTINCT stringsub(car_fee_hostname,1,2)

=》
SQL code
select distinct SUBSTRING(car_fee_hostname,1,3) as car_fee_hostname from