public static DataTable SelectSQL(string a)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand(a, connection))
{
using (SqlDataAdapter da = new SqlDataAdapter(command))
{
DataSet ds = new DataSet();
try
{
da.Fill(ds, "ds");
command.Parameters.Clear();
}
catch (System.Data.SqlClient.SqlException ex)
{
throw new Exception(ex.Message);
}
connection.Close();
return ds.Tables[0];
}
}
}
}
public string SelectQuan()
{
string name = System.Web.HttpContext.Current.Request["TextBox1"].ToString();
string str = "select * from B join C on B.name = C.姓名";
if (name == "")
{
System.Web.HttpContext.Current.Response.Write("请输入名字");
}
else if (name != "" && name.IndexOf(',') == -1)
{
str = "select * from B join C on B.name = C.姓名 where B.name = '" + name + "'";
SelectSQL("select * from B join C on B.name = C.姓名");
string[] arr = SelectSQL("select * from B join C on B.name = C.姓名").AsEnumerable().Select(d => d.Field
int w = 0;
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] == name)
{
w++;
}
}
if (w != 1)
{
System.Web.HttpContext.Current.Response.Write("你输入的名字不存在");
}
}
else if (name.IndexOf(',') > -1)
{
str = "select * from B join C on B.name = C.姓名 where name =";
SelectSQL("select name from B");
string[] arr = SelectSQL("select name from B").AsEnumerable().Select(d => d.Field
string[] array = name.Split(',');//
int count = array.Length;
int count1 = 0;
for (int k = 0; k < array.Length; k++)
{
for (int j = 0; j < arr.Length; j++)
{
if (arr[j] == array[k])
{
count1 += 1; //计数器
}
}
}
if (count1 != count)
{
System.Web.HttpContext.Current.Response.Write("你输入的名字中有不存在的人名");
}
for (int i = 0; i < array.Length; i++)
{
str += "'" + array[i] + "'";
if (i != array.Length - 1)
{
str += "or B.name =";
}
}
}
return str;
}
这种情况是怎么回事,GridView控件都绑定了,是哪出问题了,求大神指点
还没有评论,来说两句吧...