TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kobinath Ram
NA
130
0
bank account to account transaction in c#
May 24 2017 8:14 AM
SqlConnection con = new SqlConnection("server=.; database=bank; user id=sa; password=;");
private void button1_Click(object sender, EventArgs e)
{
int fano, tano, bal;
fano = int.Parse(textBox1.Text);
tano = int.Parse(textBox2.Text);
bal = int.Parse(textBox3.Text);
SqlCommand cmd = con.CreateCommand();
SqlTransaction transaction = null;
try
{
con.Open();
transaction = con.BeginTransaction();
cmd.Transaction = transaction;
cmd.CommandText = "update accountholder set Balance= '"+bal+"'-Balance where acno= '" + textBox1.Text + "'";
cmd.ExecuteNonQuery();
cmd.CommandText = "update accountholder set Balance= '" + bal + "'+ Balance where acno= '" + textBox2.Text + "'";
cmd.ExecuteNonQuery();
cmd.CommandText = "insert into TransferDetails (acno1,acno2,Balance) VALUES (@acno1,@acno2,@Balance)";
cmd.Parameters.AddWithValue("@acno1", textBox1.Text);
cmd.Parameters.AddWithValue("@acno2", textBox2.Text);
cmd.Parameters.AddWithValue("@Balance", textBox3.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("suceess");
transaction.Commit();
}
catch(Exception ex)
{
transaction.Rollback();
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
I wanted to transfer money from one account to another. The error occurred is SQL syntax based on where clause.i have atached the source code also. please correct the error
cmd.CommandText = "update accountholder set Balance= '"+bal+"'-Balance where acno= '" + textBox1.Text + "'";
cmd.ExecuteNonQuery();
cmd.CommandText = "update accountholder set Balance= '" + bal + "'+ Balance where acno= '" + textBox2.Text + "'";
this line were getting error while running the code thanks
Attachment:
WindowsFormsApplication6.rar
Reply
Answers (
4
)
To create package in ssis for xml file and parse it and get
i want to Fetch data from database based on Order Bill No