62,046
社区成员
发帖
与我相关
我的任务
分享
namespace ZKBS.DataSet1TableAdapters
{
public partial class T_JobTimeTableAdapter : System.ComponentModel.Component
{
System.Data.SqlClient.SqlCommand customCommand = new System.Data.SqlClient.SqlCommand();
public DataSet1.T_JobTimeDataTable/*这个,换成你自己的Table类型*/ Search(System.Collections.ArrayList Columns, System.Collections.ArrayList Values)
{
DataSet1.T_JobTimeDataTable table = new DataSet1.T_JobTimeDataTable();
string customString = "SELECT * FROM dbo.T_JobTime ";
/*
* 以下是根据传进来的参数合成参数化查询的
* 请根据具体情况修改实现
* 本代码仅仅为了说明如何实现类型化数据集扩展
* 并不一定适合实际情况
*
*/
if (Columns != null && Values != null)
{
customCommand.Connection = this.Connection;//自动生成代码中的属性
customCommand.Parameters.Clear();
for (int i = 0; i < Columns.Count; i++)
{
temp += " and " + Columns[i].ToString() + " like @p" + (i + 0) + " ";
customCommand.Parameters.Add("@p" + (i + 0), System.Data.SqlDbType.VarChar);
if (string.IsNullOrEmpty(Values[i].ToString()))
{
customCommand.Parameters[i + 0].Value = "";
}
else
{
customCommand.Parameters[i + 0].Value = "%" + Values[i].ToString() + "%";
}
}
customCommand.CommandText = customString + temp;
this.Adapter.SelectCommand = customCommand;
this.Adapter.Fill(table);
return table;
}
else
{
throw (new System.Exception("参数错误!"));
}
}
}
}