ASP.NET数据库查询问题
stringstr="";stringstr1="";stringStationName=this.TextBox2.Text;stringsqlconn=@"Serve...
string str = "";
string str1 = "";
string StationName = this.TextBox2.Text;
string sqlconn = @"Server = .;DataBase = Bus; Integrated Security = SSPI;";
SqlConnection myConnection = new SqlConnection(sqlconn);
SqlCommand myCommand = new SqlCommand("select * from RouteTable where Station='" + StationName + "'", myConnection);
SqlDataAdapter Adapter = new SqlDataAdapter();
SqlCommandBuilder cmdB = new SqlCommandBuilder(Adapter);
Adapter.SelectCommand = myCommand;
DataSet myDs = new DataSet();
Adapter.Fill(myDs);
str += "<font size=4><strong>经过" + StationName + "车次如下:</strong></font><br>";
for (int i = 0; i < myDs.Tables[0].Rows.Count; i++)
{
if (myDs.Tables[0].Rows[i][1].ToString() == this.TextBox2.Text.Trim())
{
str1 += "<font color=red>" + myDs.Tables[0].Rows[i][i].ToString() + "</font>路<br>";
}
}
this.Label23.Text = str;
this.Label2.Text = str1;
要查找出符合输入站名的所有线路,但是目前只能查到:
经过朝阳广场车次如下:
14路
朝阳广场路 展开
string str1 = "";
string StationName = this.TextBox2.Text;
string sqlconn = @"Server = .;DataBase = Bus; Integrated Security = SSPI;";
SqlConnection myConnection = new SqlConnection(sqlconn);
SqlCommand myCommand = new SqlCommand("select * from RouteTable where Station='" + StationName + "'", myConnection);
SqlDataAdapter Adapter = new SqlDataAdapter();
SqlCommandBuilder cmdB = new SqlCommandBuilder(Adapter);
Adapter.SelectCommand = myCommand;
DataSet myDs = new DataSet();
Adapter.Fill(myDs);
str += "<font size=4><strong>经过" + StationName + "车次如下:</strong></font><br>";
for (int i = 0; i < myDs.Tables[0].Rows.Count; i++)
{
if (myDs.Tables[0].Rows[i][1].ToString() == this.TextBox2.Text.Trim())
{
str1 += "<font color=red>" + myDs.Tables[0].Rows[i][i].ToString() + "</font>路<br>";
}
}
this.Label23.Text = str;
this.Label2.Text = str1;
要查找出符合输入站名的所有线路,但是目前只能查到:
经过朝阳广场车次如下:
14路
朝阳广场路 展开
1个回答
展开全部
You already have two rows returned. that means your code is correct.
Probably, you should check the table to see if you still got 2 records using
"select route, station from routetable where station=@stationname " (like %@stationname%)
Probably, you should check the table to see if you still got 2 records using
"select route, station from routetable where station=@stationname " (like %@stationname%)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询