客户欢迎页面询问帐户中的客户ID
我想连接两个表单,1当你单击go按钮时,表单将转到表单#2并将列表显示到表格中。
表格1:从账户表中收取Cid:http://puu.sh/hnp4G/eeb8da0a87.png
public partial class WelcomeCust : Form
{
OleDbConnection db = new OleDbConnection();
OleDbDataAdapter da = new OleDbDataAdapter();
DataTable dt = new DataTable();
public WelcomeCust()
{
InitializeComponent();
db.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\ChattBankMDB.mdb";
}
private void button1_Click(object sender, EventArgs e)
{
//Code for looking up the
using (OleDbCommand da = new OleDbCommand("select Cid From Accounts", db))
{
db.Open();
DataTable schema = db.GetSchema("Tables");
List<Accounts> TableNames = new List<Accounts>();
foreach (DataRow row in schema.Rows)
{
TableNames.Add(row[0].ToString());
}
da.Parameters.AddWithValue("@Cid", textBox1.Text);
da.ExecuteNonQuery();
return TableNames;
db.Close();
}
}
表单2:显示您的帐户表:http://puu.sh/hnpgr/e1d31930cf.png
public partial class CustomerAccounts : Form
{
public CustomerAccounts()
{
InitializeComponent();
}
private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
{
}
}
}
TableNames.Add(row[0].ToString());
和return TableNames();
也给了我错误。:
Error 2 Argument 1: cannot convert from 'string' to 'ChattBank.Accounts'
Error 3 Since 'ChattBank.WelcomeCust.button1_Click(object, System.EventArgs)' returns void, a return keyword must not be followed by an object expression
答案 0 :(得分:0)
错误非常简单,您的列表期望对象Accounts
,但是您传递了一个字符串,并且由于此方法的返回值为void,因此您不应该使用return语句。如果您需要在其他方法中访问TableNames
,请尝试将其定义为WelcomeCust
类的私有字段