asp.net不包含insert的定义找不到可接受类型为“DBConn.Class1”的第一个参数的扩展方法insert 15
usingDBConn;publicpartialclassRegist:System.Web.UI.Page{protectedvoidPage_Load(object...
using DBConn;
public partial class Regist : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
String id = TextBox1.Text;
String name = TextBox2.Text;
String password = TextBox3.Text;
String sex = TextBox5.Text;
String age = TextBox6.Text;
String college = TextBox7.Text;
String tel = TextBox8.Text;
String email = TextBox9.Text;
String qq = TextBox10.Text;
String picture = TextBox11.Text;
String intro = TextBox12.Text;
String conn = ConfigurationManager.AppSettings["MyConnectionString"];
Class1 DBConn = new Class1(conn);
{
DBConn.regist(id,name,password,sex,age,college,tel,email,qq,picture,intro);
DBConn.insert(id,password);//我想在这里调用这个方法,却显示错误:不包含这个insert定义
Response.Redirect("Login.aspx");
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace DBConn
{
public void insert(String id, String password)//我在这里已经定义了呀?????
{
SqlConnection connection = getConn();
connection.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandText = "insert into userinfo values('" + id + "','" + password + "')";
cmd.ExecuteNonQuery();
connection.Close();
}
} 展开
public partial class Regist : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
String id = TextBox1.Text;
String name = TextBox2.Text;
String password = TextBox3.Text;
String sex = TextBox5.Text;
String age = TextBox6.Text;
String college = TextBox7.Text;
String tel = TextBox8.Text;
String email = TextBox9.Text;
String qq = TextBox10.Text;
String picture = TextBox11.Text;
String intro = TextBox12.Text;
String conn = ConfigurationManager.AppSettings["MyConnectionString"];
Class1 DBConn = new Class1(conn);
{
DBConn.regist(id,name,password,sex,age,college,tel,email,qq,picture,intro);
DBConn.insert(id,password);//我想在这里调用这个方法,却显示错误:不包含这个insert定义
Response.Redirect("Login.aspx");
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace DBConn
{
public void insert(String id, String password)//我在这里已经定义了呀?????
{
SqlConnection connection = getConn();
connection.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandText = "insert into userinfo values('" + id + "','" + password + "')";
cmd.ExecuteNonQuery();
connection.Close();
}
} 展开
1个回答
展开全部
请问你的Class1在哪里,你的insert方法放在命名空间DBConn下,你知道命名空间和类的区别?
更多追问追答
追问
namespace DBConn
{ public class Class1
。。。。
public void insert(String id, String password)
{ 。。。}
其实是这样的 不小心删掉了
追答
有个命名空间是DBConn ,你在Class1实例化对象返回的对象也是DBConn有冲突,你将此对象更改成别的!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询