读书人

c#函数调用有关问题

发布时间: 2012-04-05 12:42:40 作者: rapoo

c#:函数调用问题。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
//using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Drawing.Drawing2D;
using System.Collections ;
using System.Globalization;

namespace denglujiemian
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Dengluing();
}


public class Test
{
public OleDbConnection myConnection;
public String connectionString;
public String id="this .textBox1 .Text .ToString ().Trim ()";
public String mima = "this .textBox2 .Text .ToString ().Trim ()";
public void Dengluing()//登陆代码
{
if(id !="" && mima !="")
{
try
{
connectionString=@"DataSource=kk;InitialCatalog=DB;IntegratedSecurity=True;
Pooling=False";

DataSet myDataSet = new DataSet();
myConnection=new OleDbConnection(connectionString );
myConnection .Open();
OleDbCommand myCmd = myConnection.CreateCommand();
myCmd.CommandText="select ID,MIMA from 身份 WHERE ID=id and MIMA=mima";


OleDbDataReader myReader = myCmd.ExecuteReader();

if(myReader.Read())//如果有这个用户
{
Form2 j = new Form2();
j.Show();
}
else
{
MessageBox.Show("您输入的用户号或密码不正确!");
}
myConnection.Close();
myCmd.Dispose();
myReader.Dispose();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}

}
}

}
}
}
错误存在于124D:\ QQ\1\denglujiemian\denglujiemian\Form1.cs当前上下文中不存在名称“Dengluing”11denglujiemian
弄不明白为什么错了。希望您能给以答复。谢谢!


[解决办法]
创建一个Test对象,然后调用dengluing()方法
[解决办法]
把 public class Test 和一对{} 删除.



[解决办法]
你把方法写在了类当中,肯定不能这样调用了。。。。。
[解决办法]
private void button1_Click(object sender, EventArgs e)
{
Test test = new test();
test.Dengluing();
}


------解决方案--------------------


是非静态方法,只能通过类的实例来访问。
[解决办法]
private void button1_Click(object sender, EventArgs e)
{
Dengluing();
}

Test test = new test();
test.Dengluing();
没有实力化当然不能调用
[解决办法]

探讨
private void button1_Click(object sender, EventArgs e)
{
Test test = new test();
test.Dengluing();
}

读书人网 >C#

热点推荐