数据库操作,如果返回SQL数据库某表中列值=something 的行数

matee 2009-04-25 05:40:15
数据库操作,如果返回SQL数据库某表中列值=something 的行数

例如:

id color
1 red
2 black
3 yellow
4 red
5 red
6 yellow
7 black
8 white


查询Red.则返回4.请问如何实现?
...全文
60 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Garnett_KG 2009-04-25
  • 打赏
  • 举报
回复

public static int accountWord(int courseNum)
{
int RowCount=0;
SQLiteConnection cn = new SQLiteConnection();
cn.ConnectionString = datasource;
cn.Open();
string sql = "select count(color) from GOODS where courseID='"+courseNum+"'";
using (SQLiteCommand cmd = new SQLiteCommand(sql))
{
cmd.Connection = cn;
RowCount=(int)cmd.ExecuteScalar();
}
cn.Close();

return RowCount;

}

matee 2009-04-25
  • 打赏
  • 举报
回复
请问如果用C#函数实现,
如:


public static int accountWord(int courseNum)
{
SQLiteConnection cn = new SQLiteConnection();
cn.ConnectionString = datasource;
cn.Open();
string sql = "select count(color) from GOODS where courseID='"+courseNum+"'";
using (SQLiteCommand cmd = new SQLiteCommand(sql))
{
cmd.Connection = cn;
cmd.ExecuteNonQuery();
}
cn.Close();

//return

}


请问 return应该如何实现? 这个值被存在哪里?
OenAuth.Net 2009-04-25
  • 打赏
  • 举报
回复
你那个RED应该是三行吧??
select count(color) from 表名 where color='red'

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧