Java教程

带参数的SQL语句

本文主要是介绍带参数的SQL语句,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、SQL语句带参数的
(1)、
public static int Updata(string sql)
{
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(sql, conn);
try
{
conn.Open();
return cmd.ExecuteNonQuery();
}
catch (Exception ex)
{

            throw ex;
        }
        finally
        {
            conn.Close();
        }
      }

  (2)
      public static int Updata(string sql,,SqlParameter[] param)
    {
        SqlConnection conn = new SqlConnection(connString);
        SqlCommand cmd = new SqlCommand(sql, conn);
        try
        {
            conn.Open();
            cmd.Parameters.AddRange(param)
            return cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {

            throw ex;
        }
        finally
        {
            conn.Close();
        }
      }
    3:SQL语言
      string sql=“Select LoginId,LoginPWD from Admin Where LoginId=@LoginId and LoginPWD=@LogindPWD”;
      SqlParameter[] parameter= new SqlParameter[]
      {
          new SqlParameter("@LoginId",objAdmin.LoginId),
           new SqlParameter("@LoginPWD",objAdmin.LoginPWD),
      }
这篇关于带参数的SQL语句的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!