求大家给一段常用的sqlcommand代码。

cppsun 2011-02-05 09:37:40
求大家给一段常用的sqlcommand代码。
最好有插入操作的。
...全文
111 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cppsun 2011-02-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wuyq11 的回复:]
using( SqlConnection sqlcon = new SqlConnection(source))
{
sqlcon.Open();
SqlCommand sqlcom = new SqlCommand("insert into ChangedFile(filed,filedtype) values(@filed,@filedtype)",sqlcon);
sql……
[/Quote]

using( SqlConnection sqlcon = new SqlConnection(source))
这段的作用是什么?
wuyq11 2011-02-05
  • 打赏
  • 举报
回复
using( SqlConnection sqlcon = new SqlConnection(source))
{
sqlcon.Open();
SqlCommand sqlcom = new SqlCommand("insert into ChangedFile(filed,filedtype) values(@filed,@filedtype)",sqlcon);
sqlcom.Parameters.Add("@filed", SqlDbType.VarChar);
sqlcom.Parameters.Add("@filedtype", SqlDbType.Int);
sqlcom.Parameters["@filed"].Value = e.FullPath;
sqlcom.Parameters["@filedtype"].Value = 1;
sqlcom.ExecuteNonQuery();
sqlcon.Close();
}
数据库操作类sqlhelper
phil999 2011-02-05
  • 打赏
  • 举报
回复
抄楼主的代码,稍稍改动了一下



string source = @" server = .;database = DB1; integrated security=SSPI ";

using(SqlConnection sqlcon = new SqlConnection(source))
{
sqlcon.Open();

SqlCommand sqlcom = sqlcon.CreateCommand();
sqlcom.CommandText = "insert into ChangedFile(filed,filedtype) values(@filed,@filedtype)";
sqlcom.Parameters.Add("@filed", SqlDbType.VarChar);
sqlcom.Parameters.Add("@filedtype", SqlDbType.Int);
sqlcom.Parameters["@filed"].Value = e.FullPath;
sqlcom.Parameters["@filedtype"].Value = 1;
sqlcom.ExecuteNonQuery();

}


xu56180825 2011-02-05
  • 打赏
  • 举报
回复
用LINQ TO SQL吧~~~这个太容易了
xujun5031 2011-02-05
  • 打赏
  • 举报
回复
SqlConnection cn= new SqlConnection(connectionString)
cn.open();
SqlCommand cmd = new SqlCommand(strSQL, cn);
cmd.ExecuteNonQuery();
cn.close();

110,534

社区成员

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

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

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