Fuzzy query problem with parameters

xiaoxiao2021-03-06  35

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; }

转载请注明原文地址:https://www.9cbs.com/read-63332.html

New Post(0)