public DataTable getProductsByName(string productType,string productName) {
SqlConnection l_SqlConnenction = new SqlConnection();
l_SqlConnenction.ConnectionString = "workstation id=OVERMIND;packet size=4096;user id=sa;password=sa;data source=OVERMIND;persist security info=False;initial catalog=wztj";
l_SqlConnenction.Open();
string SelectCommandText = "select * from Product where name like @produtName";
SqlCommand l_SqlCommand = new SqlCommand(SelectCommandText,l_SqlConnenction);
l_SqlCommand.Parameters.Add("@productType",productType);
SqlParameter par1 = new SqlParameter("@produtName",SqlDbType.VarChar,500);
par1.Value ="%"+ productName+"%";
l_SqlCommand.Parameters.Add(par1); DataSet dataset = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = l_SqlCommand;
adapter.Fill(dataset,"product");
DataTable dt = dataset.Tables["product"];
l_SqlConnenction.Close();
return dt;
}
关于带参数的模糊查询问题
最新推荐文章于 2023-04-11 00:03:26 发布
此博客展示了一段C#代码,用于通过产品类型和名称获取产品数据。代码创建了SQL连接,设置连接字符串,执行SQL查询,将查询结果填充到DataSet中,最后返回包含产品数据的DataTable,涉及数据库操作和数据处理。
997

被折叠的 条评论
为什么被折叠?



