c# winfom问题
做一个银行的存取款系统 碰到下面问题 做到转账系统时 我思路是a用户取出钱 b用户存入钱 就在存款和取款的基础上改了一下代码 运行也不报错 就是一直没有效果String str1 = "Server=localhost\\MSSQLSERVER1;uid=sa;pwd=sql;database=bank";
SqlConnection con = new SqlConnection(str1);
con.Open();
SqlDataAdapter da3 = new SqlDataAdapter("select 账户号,金额 from card where 账户号='" + usercard3 + "'and 密码='" + userpwd31 + "'", con);
DataTable dt3 = new DataTable();
da3.Fill(dt3);
SqlDataAdapter da4 = new SqlDataAdapter("select 账户号,金额 from card where 账户号='" + usercard4 + "'", con);
DataTable dt4 = new DataTable();
da4.Fill(dt4);
textBox19.Text = dt3.Rows[0][0].ToString();
string m3 = dt3.Rows[0][1].ToString();
string m4 = dt4.Rows[0][1].ToString();
//计算总金额
float money32;
money32 = Convert.ToSingle(m3);
float moneyx3;
moneyx3 = Convert.ToSingle(money3);
float moneyxx3 = money32 - moneyx3;
if (moneyxx3 < 0)
{
MessageBox.Show("账户金额不足!");
textBox24.Clear();
textBox14.Text = "";
textBox20.Text = "";
return;
}
float money42;
money42 = Convert.ToSingle(m4);
float moneyxx4 = money42 + moneyx3;
//更新card表里金额的记录
string mon3 = moneyxx3.ToString();
string mon4 = moneyxx4.ToString();
textBox1.Text = mon3;
SqlCommand com5 = new SqlCommand();
com5.CommandText = "update card set 金额='" + mon3 + "' where 账户号='" + usercard3 + "'";
com5.Connection = con;
//con.Open();
com5.ExecuteNonQuery();
com5.Dispose();
con.Close();
SqlCommand com7 = new SqlCommand();
com7.CommandText = "update card set 金额='" + mon4+ "' where 账户号='" + usercard4 + "'";
com7.Connection = con;
con.Open();
com7.ExecuteNonQuery();
com7.Dispose();
con.Close();
//插入记录
SqlCommand com6 = new SqlCommand();
com6.CommandText = "insert into record (账户号,日期,存取类型,存取金额)values('" + usercard3 + "','" + date1 + "','转出','" + money3 + "')";
com6.Connection = con;
con.Open();
com6.ExecuteNonQuery();
com6.Dispose();
con.Close();
MessageBox.Show("操作成功!");
textBox1.Clear();
textBox21.Clear();
textBox23.Clear();
textBox20.Clear();
textBox14.Clear();
textBox19.Clear();
textBox24.Clear();
初学 希望能有人指导下 C# --------------------编程问答-------------------- 是不是太长了都没人看啊 --------------------编程问答-------------------- 1、代码没有用代码模式发布
2、你的变量名实在让人没有兴趣继续看下去,全是什么23、7之类的。 --------------------编程问答-------------------- 还有你的sql代码部分,字段都是中文,都是直接拼接sql而未用带参数的sql语句的方式。调用DAO操作,是否可以封装一下呢?需改进的太多。 --------------------编程问答-------------------- 你连个try...catch都没有,怎么就知道没错呢?
转账,都不控制事务,钱没到账你负责啊? --------------------编程问答-------------------- 不是啊,我是发了其中的一段= =我想知道这里面有什么问题吗 try catch都有的 是不是哪里格式上有问题那 还是那个sqlcommand下面有问题呢 --------------------编程问答-------------------- 不好意思 第一次发帖 不知道还有这个格式 我发个全的
private void textBox23_TextChanged(object sender, EventArgs e)--------------------编程问答-------------------- debug 哪里有错跟一下就知道了
{
usercard3 = textBox23.Text;
}
private void textBox21_TextChanged(object sender, EventArgs e)
{
usercard4 = textBox21.Text;
}
private void textBox24_TextChanged(object sender, EventArgs e)
{
money3 = textBox24.Text;
}
private void textBox20_TextChanged(object sender, EventArgs e)
{
userpwd31 = textBox20.Text;
//提供密码字符掩码
textBox20.PasswordChar = '*';
}
private void textBox14_TextChanged(object sender, EventArgs e)
{
userpwd32 = textBox14.Text;
//提供密码字符掩码
textBox14.PasswordChar = '*';
}
private void button7_Click(object sender, EventArgs e)
{
try
{
if (userpwd31 != userpwd32)
{
MessageBox.Show("两次密码不一致!");
textBox14.Text = "";
textBox20.Text = "";
return;
}
else
{
String str1 = "Server=localhost\\MSSQLSERVER1;uid=sa;pwd=sql;database=bank";
SqlConnection con = new SqlConnection(str1);
con.Open();
SqlDataAdapter da3 = new SqlDataAdapter("select 账户号,金额 from card where 账户号='" + usercard3 + "'and 密码='" + userpwd31 + "'", con);
DataTable dt3 = new DataTable();
da3.Fill(dt3);
SqlDataAdapter da4 = new SqlDataAdapter("select 账户号,金额 from card where 账户号='" + usercard4 + "'", con);
DataTable dt4 = new DataTable();
da4.Fill(dt4);
textBox19.Text = dt3.Rows[0][0].ToString();
string m3 = dt3.Rows[0][1].ToString();
string m4 = dt4.Rows[0][1].ToString();
//计算总金额
float money32;
money32 = Convert.ToSingle(m3);
float moneyx3;
moneyx3 = Convert.ToSingle(money3);
float moneyxx3 = money32 - moneyx3;
if (moneyxx3 < 0)
{
MessageBox.Show("账户金额不足!");
textBox24.Clear();
textBox14.Text = "";
textBox20.Text = "";
return;
}
float money42;
money42 = Convert.ToSingle(m4);
float moneyxx4 = money42 + moneyx3;
//更新card表里金额的记录
string mon3 = moneyxx3.ToString();
string mon4 = moneyxx4.ToString();
textBox1.Text = mon3;
SqlCommand com5 = new SqlCommand();
com5.CommandText = "update card set 金额='" + mon3 + "' where 账户号='" + usercard3 + "'";
com5.Connection = con;
//con.Open();
com5.ExecuteNonQuery();
com5.Dispose();
con.Close();
SqlCommand com7 = new SqlCommand();
com7.CommandText = "update card set 金额='" + mon4+ "' where 账户号='" + usercard4 + "'";
com7.Connection = con;
con.Open();
com7.ExecuteNonQuery();
com7.Dispose();
con.Close();
//插入记录
SqlCommand com6 = new SqlCommand();
com6.CommandText = "insert into record (账户号,日期,存取类型,存取金额)values('" + usercard3 + "','" + date1 + "','转出','" + money3 + "')";
com6.Connection = con;
con.Open();
com6.ExecuteNonQuery();
com6.Dispose();
con.Close();
MessageBox.Show("操作成功!");
textBox1.Clear();
textBox21.Clear();
textBox23.Clear();
textBox20.Clear();
textBox14.Clear();
textBox19.Clear();
textBox24.Clear();
}
}
catch (System.Exception)
{
MessageBox.Show("账户不存在或密码错误,请核对后重新输入!");
con.Close();
return;
}
}
private void button6_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox21.Clear();
textBox23.Clear();
textBox20.Clear();
textBox14.Clear();
textBox19.Clear();
textBox24.Clear();
}
补充:.NET技术 , C#