跪求C#大神看一下,这段代码是什么意思,最好每句能帮我注释下,感激不尽! 5
publicinthsgexucute(stringsql){//myConnection.Open();SqlConnectionconn=newSqlConnecti...
public int hsgexucute(string sql)
{
//myConnection.Open();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = connstring;
SqlCommand myCommand = new SqlCommand(sql, conn);
SqlCommand cmd = new SqlCommand(sql, conn);
try
{
conn.Open();
myCommand.ExecuteNonQuery();
return 1;
}
catch(Exception e)
{
throw e;
//Console.WriteLine("SqlException:{0}",SQLexc);
//return 0;
}
finally
{
conn.Close();
}
} 展开
{
//myConnection.Open();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = connstring;
SqlCommand myCommand = new SqlCommand(sql, conn);
SqlCommand cmd = new SqlCommand(sql, conn);
try
{
conn.Open();
myCommand.ExecuteNonQuery();
return 1;
}
catch(Exception e)
{
throw e;
//Console.WriteLine("SqlException:{0}",SQLexc);
//return 0;
}
finally
{
conn.Close();
}
} 展开
1个回答
展开全部
SqlConnection conn = new SqlConnection(); //申请个sqlserver 的链接对象
conn.ConnectionString = connstring; //链接字符串,就也是sqlserver的地址信息
SqlCommand myCommand = new SqlCommand(sql, conn);//操作sql的命令对象
conn.Open();//打开链接
myCommand.ExecuteNonQuery();//执行sql,不用返回值
conn.ConnectionString = connstring; //链接字符串,就也是sqlserver的地址信息
SqlCommand myCommand = new SqlCommand(sql, conn);//操作sql的命令对象
conn.Open();//打开链接
myCommand.ExecuteNonQuery();//执行sql,不用返回值
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询