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);
}
}
}
}
}
}
错误存在于1 24 D:\ QQ\1\denglujiemian\denglujiemian\Form1.cs 当前上下文中不存在名称“Dengluing” 11 denglujiemian
弄不明白为什么错了。希望您能给以答复。谢谢!
------解决方案--------------------创建一个Test对象,然后调用dengluing()方法
------解决方案--------------------把 public class Test 和一对{} 删除.
------解决方案--------------------你把方法写在了类当中,肯定不能这样调用了。。。。。
------解决方案--------------------private void button1_Click(object sender, EventArgs e)
{
Test test = new test();
test.Dengluing();
}
------解决方案--------------------