错了 ,错了 ,都写成改后的函数啦 ,对不起
=======================================================================///////////////////////////////原函数,两个参数id ,tablename/////////
public string GetMaxId(string id,string tablename)
{
string str_Key;
string str_Sql="select top 1 "+id+" from "+tablename+" order by "+id+" desc";
if (GetRowCount(str_Sql)==0)
{
str_Key="1";
}
else
{
GetRowRecord(str_Sql);
str_Key=(int.Parse(dr[id].ToString())+1).ToString(); // 获得数据库表key值
}
return str_Key;
}=========我把它改了 ,多加了两个参数 count,countvalue就同不过,是我的select 语句写错了吗 ?=====public string GetMaxId(string id,string tablename,string count,string countvalue)
{
string str_Key;
string str_Sql="select top 1 "+id+" from "+tablename+" where "+count+"="+countvalue+" order by "+id+" desc";
if (GetRowCount(str_Sql)==0)
{
str_Key="1";
}
else
{
GetRowRecord(str_Sql);
str_Key=(int.Parse(dr[id].ToString())+1).ToString(); // 获得数据库表key值
}
return str_Key;
}
=======================================================================///////////////////////////////原函数,两个参数id ,tablename/////////
public string GetMaxId(string id,string tablename)
{
string str_Key;
string str_Sql="select top 1 "+id+" from "+tablename+" order by "+id+" desc";
if (GetRowCount(str_Sql)==0)
{
str_Key="1";
}
else
{
GetRowRecord(str_Sql);
str_Key=(int.Parse(dr[id].ToString())+1).ToString(); // 获得数据库表key值
}
return str_Key;
}=========我把它改了 ,多加了两个参数 count,countvalue就同不过,是我的select 语句写错了吗 ?=====public string GetMaxId(string id,string tablename,string count,string countvalue)
{
string str_Key;
string str_Sql="select top 1 "+id+" from "+tablename+" where "+count+"="+countvalue+" order by "+id+" desc";
if (GetRowCount(str_Sql)==0)
{
str_Key="1";
}
else
{
GetRowRecord(str_Sql);
str_Key=(int.Parse(dr[id].ToString())+1).ToString(); // 获得数据库表key值
}
return str_Key;
}
解决方案 »
- 用asp.net代码如何收缩SQL数据库?
- 同志们,大家帮小弟做一个asp.net的期末作业啊!急求~
- ireaper
- 求教:我想做类似网易网盘那种样式,怎么能把文件夹和文件在一块儿显示出来,谢谢
- 我打包安装后,浏览网站出现 allowDefinition='MachineToApplication' 错误怎么改啊!!!
- Repeater 控件绑定数据后不显示的问题
- 做了个网站,asp.net(c#),问题是如何把session的有效时间设置成1天,谢谢!
- 菜鸟问题,希望大家帮助!!!
- select top 的问题~~来帮帮我啊~~~!!!
- 奇怪,为什么会报错:使用了未赋值的局部变量a
- C#语句如何转为VB.Net?
- 如何将两个项目合并,共享两个项目的Session?
//////////////////////
“top 1” 是什么意思呀 ?
指定只从查询结果集中输出前 n 行。
如果还指定了 percent,则只从结果集中输出前百分之 n 行。 (0<n<100)
行 76: myAdapter = new SqlDataAdapter(str_Sql,myConnection);
行 77: ds = new DataSet();
行 78: myAdapter.Fill(ds);
行 79: }
行 80: /// <summary>
在这呢
{
Open();
myAdapter = new SqlDataAdapter(str_Sql,myConnection);
ds = new DataSet();
myAdapter.Fill(ds);
}
================================================================================
public void Fill(string tabname,string sql)
{
Open();
myAdapter = new SqlDataAdapter(sql,myConnection);
ds = new DataSet();
myAdapter.Fill(ds,tabname);
}
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
public int GetRowCount(string str_Sql)
{
Fill(str_Sql);
try
{
int count=ds.Tables[0].Rows.Count;
ds.Clear();
myConnection.Close();
return count;
}
catch
{
ds.Clear();
myConnection.Close();
return 0;
}
}
================================================================================
sql中用于寻找最大值的一般用这个方法
select max(xx) x from table where xxx order by xx
你的sql语句是动态生成的,里面用了好多变量,无法确知最终的sql语句是否正确,用tongtianming(金银妖瞳) 说的Response.Write方法将你的sql语句写出来看看,然后用查询分析器运行一下看语法是否正确,或者帖到这里也可以。