SqlConnection con = new SqlConnection("server=(local);uid=sa;pwd=sa;database=tttttt");
SqlDataAdapter sap = new SqlDataAdapter();
sap.SelectCommand = new SqlCommand("select * from inf_county");
sap.SelectCommand.Connection = con; DataSet ds = new DataSet(); sap.Fill(ds); ds.Tables[0].Rows.Count就是了
SqlDataAdapter sap = new SqlDataAdapter();
sap.SelectCommand = new SqlCommand("select * from inf_county");
sap.SelectCommand.Connection = con; DataSet ds = new DataSet(); sap.Fill(ds); ds.Tables[0].Rows.Count就是了
SqlConnection m_Conn = new SqlConnection(m_ConnStr);
SqlDataAdapter m_Da = new SqlDataAdapter("select title from titles",m_Conn); DataSet m_Ds = new DataSet();
m_Da.Fill(m_Ds); int i = m_Ds.Tables["Titles"].Rows.Count ); //i返回结果集的行数
public int GetRsCount(string table_name)
{
string strSql;
int intCount;
Open();
strSql="select count(*) from "+table_name;
SqlCommand cmd=new SqlCommand(strSql,cn);
intCount=(int)cmd.ExecuteScalar();
Close();
return intCount;
}
......
SqlDataReader myReader=SqlCom.ExcuteReader();
int iCount=0;
if (myReader.Read())
{
iCount=myReader.GetInt32(0);//返回记录数
}
利用iCount大小声明数组
myReader.NextResult();
while (myReader.Read())
{
读取记录到数组
}
' / .- .
. .- .-
./ .--...
.-------- 0 .--
/ .......
' ..
'........ ----
. --..
. .---.. -
分 o . ' -.
分 / '
/ ' ' '
\-分--/....... . ' ' ' '
\ __/ - - -' ' ' '
' ' ' '
o ' ' ' '
' ' '
-..'.----------.
I ----------
/////////.
SqlConnection con = new ("联接字符串");
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "select * from A";
int count = cmd.ExecuteNonQuery();// Object count = cmd.ExecuteScalar();(语句2)
语句2 用来和这们的语句配合的:select count(*) from A
count就是你想要的行数!
ExecuteNonQuery()返回所影响的行数,但不返回任何结果
ExcuteScalar()要返回结果的,这样我想你应该明白了吧!