C# SQL占位符
string connString = ConfigurationManager.AppSettings["SqlConn"].ToString(); var conn=new SqlConnection(connString); //var cmd = new SqlCommand("SELECT alliance,ballid FROM talliance with(nolock) WHERE type=8 AND alliance like ‘%‘+@alliance;"); var cmd = new SqlCommand("SELECT alliance,ballid FROM talliance WHERE type=8 AND alliance like ‘‘+ @alliance +‘%‘;"); cmd.Parameters.Add(new SqlParameter("@alliance", SqlDbType.NVarChar, 1000)); //cmd.Parameters[0].Value = "||ATP Sydney international match"; cmd.Parameters[0].Value = "ATP 悉尼國際賽||"; cmd.Connection = conn; conn.Open(); var dr = cmd.ExecuteReader(); while (dr.Read()) { Console.WriteLine("alliance:"+dr[0].ToString() +"---"+"ballid:"+dr[1].ToString()); } dr.Dispose(); conn.Close(); Console.ReadKey();
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。