问题描述
- asp.net 报错,求大神帮解决
-
//这是业务类 public class userService { public static bool addUser(int id,string username,string password,string name,string tel,string addr,string email){ string myStr = ConfigurationManager.AppSettings["conStr"].ToString(); SqlConnection myConn = new SqlConnection(myStr); string sqlstr = "insert into user (_id,_username,_password,_name,_tel,_addr,_email) values(" + id + "'" + username + "'" + "'" + password + "'" + "'" + name + "'" + "'" + tel + "'" + "'" + addr + "'" + "'" + email + "'" + ")"; SqlCommand comm = new SqlCommand(sqlstr,myConn); if(myConn.State==ConnectionState.Closed){ myConn.Open(); } int records = Convert.ToInt32(comm.ExecuteNonQuery()); if (records > 0) { return true; } else { return false; } } } //这是对业务类的调用 protected void btn_reg_Click(object sender, EventArgs e){ bool flag = false; string userName = t_un.Text; string passWord = t_pwd.Text; string name = t_n.Text; string tel = t_tel.Text; string addr = t_add.Text; string email = t_email.Text; flag= userService.addUser(1,userName,passWord,name,tel,addr,email); if (flag == true) { Response.Write("添加成功"); } else { Response.Write("添加失败"); } }
报错截图
以前写Java就是这么干的,业务类与调用分开,不知道asp.net有啥要求,第一次写asp.net,求大神帮助
解决方案
这个没有一定标准,一般你想怎样就怎样写,根据项目框架定,一般都会分层些。
解决方案二:
是可以这样写的,,,,,,
时间: 2024-11-05 14:48:32