高分求下面asp代码转成c#代码。谢谢了
sql="select * from article where (articleid is null)"
rs.open sql,conn,1,3
rs.addnew
rs("title")=title
rs("content")=content
rs("dateandtime")=date()
rs.update
articleid=rs("articleid")
问题点数:50、回复次数:11Top
1 楼cabee()回复于 2006-03-25 23:07:21 得分 0
markTop
2 楼liudng(如何取消CSDN自动往我邮箱里发广告信?更换垃圾邮件专收邮箱!)回复于 2006-03-25 23:14:10 得分 20
SqlCommand command = new SqlCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "insert into article (title,content,dateandtime,articleid) value (@title,@content,@dateandtime,@articleid)";
command.Parameters.Add(new SqlParameter("@title", title));
command.Parameters.Add(new SqlParameter("@content", content));
command.Parameters.Add(new SqlParameter("@dateandtime", dateandtime));
command.Parameters.Add(new SqlParameter("@articleid", articleid));
using (SqlConnection connection = new SqlConnection(_Connection))
{
command.Connection = connection;
connection.Open();
command.ExecuteNonQuery();
}Top
3 楼liudng(如何取消CSDN自动往我邮箱里发广告信?更换垃圾邮件专收邮箱!)回复于 2006-03-25 23:16:45 得分 10
public Insert(string title,string content,string dateandtime, string articleid)
{
SqlCommand command = new SqlCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "insert into article (title,content,dateandtime,articleid) value (@title,@content,@dateandtime,@articleid)";
command.Parameters.Add(new SqlParameter("@title", title));
command.Parameters.Add(new SqlParameter("@content", content));
command.Parameters.Add(new SqlParameter("@dateandtime", dateandtime));
command.Parameters.Add(new SqlParameter("@articleid", articleid));
using (SqlConnection connection = new SqlConnection("Data Source=localhost;Initial Catalog=DatabaseName;Integrated Security=True"))
{
command.Connection = connection;
connection.Open();
command.ExecuteNonQuery();
}
}Top
4 楼booro(特鸟飞勤)回复于 2006-03-25 23:20:20 得分 0
都不明白我的意思啊。唉。在ACCESS中怎么样能取得自动生成ID值。。。。
这个在ACCESS中能实现吗。。。Top
5 楼liudng(如何取消CSDN自动往我邮箱里发广告信?更换垃圾邮件专收邮箱!)回复于 2006-03-25 23:24:54 得分 0
把连接字符串改为ACCESS的就可以了呀,
取得Access中自动生成的ID的SQL 语句:Select articleid from article order by articleid descTop
6 楼booro(特鸟飞勤)回复于 2006-03-26 00:11:42 得分 0
假如有一个TOPIC的表,自动生成的ID 我添加了一个记录,那我怎么可以在添加完的同时返回ID值给我啊Top
7 楼zhuangjunx(星晨)回复于 2006-03-26 00:33:25 得分 0
关注Top
8 楼yybb520(bbyy)回复于 2006-03-26 00:39:26 得分 10
添完了查一次就是了嘛!Select id from article order by id descTop
9 楼booro(特鸟飞勤)回复于 2006-03-26 09:31:09 得分 0
要是这样的话我就不能上来提问了。。Top
10 楼liudng(如何取消CSDN自动往我邮箱里发广告信?更换垃圾邮件专收邮箱!)回复于 2006-03-26 09:39:30 得分 10
因为ArticleID是自动生成的,不好在添加之后取得,因为如果同时还有其它用户在添加的话,返回的ID是不对的。
如果非要返回ID的话,建议不要使用自动编号,改用SQL Server的GUID,可以在添加之前生成GUID,Top
11 楼booro(特鸟飞勤)回复于 2006-03-26 10:37:01 得分 0
SQL我就可以解决这个问题 就是ACCESS就不行,不知道为什么。晕死了。
但是我看到动网的数据库他们的表也是分开的,不知道他们是怎么写的Top




