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

2017-11-06  本文已影响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

上一篇 下一篇

猜你喜欢

热点阅读