美文网首页
Sql语句辅助类(数据库通用)

Sql语句辅助类(数据库通用)

作者: 迷失圣诞 | 来源:发表于2017-11-06 11:14 被阅读0次

private const string sql = "Data Source=.;Initial Catalog=auto;User=sa;Pwd=sasa";

SqlConnection con = null;

#region 得到command

public SqlCommand getcommand(string str)

{

con = new SqlConnection(sql);

con.Open();

SqlCommand com=new SqlCommand(str,con);

return com;

}

#endregion

#region 得到Datareader方法

public SqlDataReader getread(string str)

{

// SqlCommand com = getcommand(str);

// SqlDataReader read = com.ExecuteReader(CommandBehavior.CloseConnection);

return getcommand(str).ExecuteReader(CommandBehavior.CloseConnection);

}

#endregion

#region 得到ExecuteNonQuery方法

public int getnonquety(string str)

{

// SqlCommand com = getcommand(str);

//int result = com.ExecuteNonQuery();

return getcommand(str).ExecuteNonQuery();

}

#endregion

#region 得到ExecuteScalar方法

public int getscalar(string str)

{

// SqlCommand com = getcommand(str);

//int result = (int)com.ExecuteScalar();

return (int)getcommand(str).ExecuteScalar();

}

#endregion

相关文章

网友评论

      本文标题:Sql语句辅助类(数据库通用)

      本文链接:https://www.haomeiwen.com/subject/ewakmxtx.html