日期:2014-05-18 浏览次数:20489 次
//num 影响行数 int num = thisCommand.ExecuteNonQuery();
------解决方案--------------------
给你改改你的方法
public Boolean RunSql(string strSql) {
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
conn.Open();
SqlCommand cmd = new SqlCommand(sQueryString, conn);
try
{
cmd.ExecuteNonQuery();
conn.Close();
}
catch (System.Exception e) {
conn.Close();
return false;
}
return true;
}
public static void Sql_Operation(string userID) { using (SqlConnection myConncetion = new SqlConnection(ConfigurationManager.AppSettings["ConnString"])) using (SqlCommand myCommand = new SqlCommand("select UserID, UserName, UserPwd from WHERE userID = @userID ", myConncetion)) { try { //构造参数 SqlParameter myParameter = new SqlParameter("@userID",SqlDbType.Int,4); //为参数赋值 myParameter.Value = Int32.Parse(userID); //将参数加入command对象的参数集合中 myCommand.Parameters.Add(myParameter); myConncetion.Open(); myCommand.ExecuteNonQuery(); } catch (Exception err) { throw new Exception("Err info:"+err.Message.ToString()) } finally { myDataAdapter.Dispose(); myConncetion.Close(); myConncetion.Dispose(); } } }