求大家给一段常用的sqlcommand代码。 求大家给一段常用的sqlcommand代码。最好有插入操作的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 SqlConnection cn= new SqlConnection(connectionString)cn.open();SqlCommand cmd = new SqlCommand(strSQL, cn);cmd.ExecuteNonQuery();cn.close(); 用LINQ TO SQL吧~~~这个太容易了 抄楼主的代码,稍稍改动了一下 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();} 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 using( SqlConnection sqlcon = new SqlConnection(source))这段的作用是什么? 更新数据 封堵端口的Dos命令 viewstate的问题 dongwei2345和he_8134请进:关于生成符合常量命名规则的字符串的讨论(正则表达式) combobox的取值问题 什么是控建的并发处理? AsyncCallback 到底是事件还是方法?怎么理解 新手入门 C# Winfrom项目,如何实现Panel控件响应键盘事件 c#开发预警提醒邮件系统WEB,请大家看看需求,给点思路。谢谢。 大家看看我这段代码问题在哪里? C# 如何制作图文 工具栏
cn.open();
SqlCommand cmd = new SqlCommand(strSQL, cn);
cmd.ExecuteNonQuery();
cn.close();
{
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();}
{
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
using( SqlConnection sqlcon = new SqlConnection(source))
这段的作用是什么?