我正在创建一个withdarw窗口我的数据库连接代码是正确的并且它在同一表单上的显示结果正确我想在下一个表单上显示结果。 我实现了代码。给我错误“由于保护级别无法访问”我搜索了很多代码但没有得到任何解决方案。
此行给出错误“rece.Default.lblbal.Text = balance;”。
这是我的代码:
namespace ATMManagementSystem
{
public partial class cust_cash_with_sav : Form
{
public cust_cash_with_sav()
{
InitializeComponent();
}
#region Default Instance
public static cust_cash_with_sav defaultInstance;
/// <summary>
/// Added by the VB.Net to C# Converter to support default instance behavour in C#
/// </summary>
public static cust_cash_with_sav Default
{
get
{
if (defaultInstance == null)
{
defaultInstance = new cust_cash_with_sav();
defaultInstance.FormClosed += new
FormClosedEventHandler(defaultInstance_FormClosed);
}
return defaultInstance;
}
}
static void defaultInstance_FormClosed(object sender,
FormClosedEventArgs e)
{
defaultInstance = null;
}
#endregion
SqlConnection con = new SqlConnection("Data Source=VAIO;Initial
Catalog=ATM;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da;
DataSet ds;
int num1;
int num2;
int total1;
string balance;
public void button1_Click(object sender, EventArgs e)
{
string sql = default(string);
DataTable Log_in = new DataTable();
try
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM user_transaction
where pin_number = " + textBox2.Text + "", con);
cmd.Connection = con;
//da.SelectCommand = cmd;
da = new SqlDataAdapter(cmd);
da.Fill(Log_in);
if (Log_in.Rows.Count > 0)
{
balance = (string)(Log_in.Rows[0]["Total"].ToString());
num1 = int.Parse(balance);
num2 = int.Parse(textBox1.Text);
if (num2 > 25000)
{
MessageBox.Show("You can Only Withdraw Php 25,000");
}
else if (num2 < 200)
{
MessageBox.Show(" Mininum withdrawal is 200");
}
else if (num1 < num2)
{
MessageBox.Show(" Insuffiecient balance");
}
else
{
total1 = num1 - num2;
rece.Default.Show();
rece.Default.lblbal.Text = balance;
rece.Default.lbldep.Hide();
rece.Default.lblwith.Text = num2.ToString();
rece.Default.lblnewbal.Text = total1.ToString();
rece.Default.lblbal.Show();
rece.Default.lbldep.Hide();
rece.Default.lblwith.Show();
rece.Default.lblnewbal.Show();
//MsgBox("success")
rece.Default.lblname.Text =
Mainmenu.Default.lblname.Text;
label2.Text = total1.ToString();
//this.Hide();
}
}
else
{
}
}
catch (Exception)
{
// MessageBox.Show(" Pls. Enter Ammount!");
//MsgBox(ex.Message)
}
textBox1.Text = "";
}
}
}
答案 0 :(得分:0)
你可以试试这个
//In Form1's
using(rece form2 = new rece())
{
form2.TheValue = someControlOnForm1.Text;
}
和...
//In rece form
//Create a public property to serve the value
public string TheValue
{
set { lblbal.Text = value;}
}