Tuesday, 16 October 2012
c sharp programming
// BY THE SPIRIT THE CREATOR OF THE WHOLE WORLD
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace testingFormuneDB
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection sqconnection;
SqlCommand sqlcommand;
string connectionstring = @"Data Source=.\SQLEXPRESS;AttachDbFilename=c:\users\abayomi\documents\visual studio 2010\Projects\testingFormuneDB\testingFormuneDB\testingMUNEProjDB.mdf;Integrated Security=True;User Instance=True";
bool flag = false;
private void btnsubmit_Click(object sender, EventArgs e)
{
bool resp= saveTotalbalance();
MessageBox.Show(resp.ToString());
}
public bool saveTotalbalance()
{
int mandatory = int.Parse(txtboxmandatory.Text);
int voluntary = int.Parse(txtboxvoluntary.Text);
int prevoiusbalance = int.Parse(txtboxpreviousbalance.Text);
int totalbalance = mandatory + voluntary + prevoiusbalance;
txtboxtotalbalance.Text = totalbalance.ToString();
sqconnection = new SqlConnection(connectionstring);
sqconnection.Open();
string commanntxt = "insert into repaymentTB (totalbalance) values('" + totalbalance + "') ";
sqlcommand = new SqlCommand(commanntxt, sqconnection);
sqlcommand.ExecuteNonQuery();
flag = true;
return flag;
}
public void retrivebalance()
{
sqconnection = new SqlConnection(connectionstring);
sqconnection.Open();
string commandtxt = "select totalbalance from repaymentTB ";
sqlcommand = new SqlCommand(commandtxt, sqconnection);
DataTable dt = new DataTable();
DataSet ds = new DataSet();
SqlDataAdapter sqldatadapter = new SqlDataAdapter(sqlcommand);
sqldatadapter.Fill(ds);
dt = ds.Tables[0];
foreach (DataRow r in dt.Rows)
{
lblpreviousbalance.Text = r["totalbalance"].ToString();
}
sqconnection.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
retrivebalance();
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment