当前位置:编程学习 > C#/ASP.NET >>

asp.net C# SQL语句传值代码

asp教程.net c# sql语句传值代码
//方法一

public int userlogin(string username, string userpass)
  {
   

  sqlcommand com = new sqlcommand(string.format("select influence from userinfo where name= '{0}' and pass= '{1}' ",username,userpass), dbconn());
  int bol;
  bol = convert.toint32(com.executescalar());
  return bol;
   
  }

 
//方法二

public static datatable dtresult(string strsql, params sqlparameter[] pars)
  {
  sqlcnn = new sqlconnection(strcnn);
  sqlcmd = new sqlcommand(strsql, sqlcnn);
  sqlcmd.commandtype = commandtype.text;
  if (pars != null && pars.length > 0)
  {
  foreach (sqlparameter par in pars)
  {
  sqlcmd.parameters.add(par);
  }
  }
  datatable dt = new datatable();
  sqladapter = new sqldataadapter(sqlcmd);
  try
  {
  cnnopen();
  sqladapter.fill(dt);
  }
  catch (exception ex)
  { }
  finally
  {
  mydispose();
  }
  return dt;
  }

补充:asp.net教程,C语言
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,