- Joined
- Sep 22, 2021
- Messages
- 21
- Reaction score
- 28
- Points
- 88
Mga boss baka may idea kayo c# .net sql connection.
public partial class Form1 : Form
{ public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//..
string connectionString = "Data Source=PC14358; Initial Catalog=PAYROLL_SYSTEM; User ID=(ojas.joseph;Password= ";
string tableName = "TBL_PAYROLL";
string columns = "[ID NO],[EMPLOYEE NAME],[DESIGNATION],[MONTHLY RATE],[HALF MONTH RATE],[REGULAR OT],[REGULAR HOLIDAY OT],[SUNDAY REST OT]," +
"[SALARY ADJUSTMENT],[GROSS PAY],[SSS CONTRIBUTION],[PHIC CONTRIBUTION],[HDMF CONTRIBUTION],[SSS LOAN],[WITHHOLDING TAX]," +
"[TAX DEFICIT],[TOTAL DEDUCTIONS],[NET PAY])";
string values =
$"'{id.Text}','{ename.Text}',' {desig.Text}','{mrate.Text}','{hrate.Text}','{regot.Text}'," +
$"'{srot.Text}','{sadj.Text}','{gpay.Text}','{sss.Text}','{phic.Text}','{hdmf.Text}','{sssloan.Text}'" +
$"'{withtax.Text}','{taxdef.Text}','{tdeduc.Text}','{netpay.Text}'";
string query = $"INSERT INTO {tableName} ({columns})VALUES({values})";
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand(query, connection))
{
//Execute the Query
command.ExecuteNonQuery();
}
}
MessageBox.Show("Record Saved", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("Error: ", ex.Message + "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void exit_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
} }
Please help me guys. Thank you
public partial class Form1 : Form
{ public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//..
string connectionString = "Data Source=PC14358; Initial Catalog=PAYROLL_SYSTEM; User ID=(ojas.joseph;Password= ";
string tableName = "TBL_PAYROLL";
string columns = "[ID NO],[EMPLOYEE NAME],[DESIGNATION],[MONTHLY RATE],[HALF MONTH RATE],[REGULAR OT],[REGULAR HOLIDAY OT],[SUNDAY REST OT]," +
"[SALARY ADJUSTMENT],[GROSS PAY],[SSS CONTRIBUTION],[PHIC CONTRIBUTION],[HDMF CONTRIBUTION],[SSS LOAN],[WITHHOLDING TAX]," +
"[TAX DEFICIT],[TOTAL DEDUCTIONS],[NET PAY])";
string values =
$"'{id.Text}','{ename.Text}',' {desig.Text}','{mrate.Text}','{hrate.Text}','{regot.Text}'," +
$"'{srot.Text}','{sadj.Text}','{gpay.Text}','{sss.Text}','{phic.Text}','{hdmf.Text}','{sssloan.Text}'" +
$"'{withtax.Text}','{taxdef.Text}','{tdeduc.Text}','{netpay.Text}'";
string query = $"INSERT INTO {tableName} ({columns})VALUES({values})";
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand(query, connection))
{
//Execute the Query
command.ExecuteNonQuery();
}
}
MessageBox.Show("Record Saved", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("Error: ", ex.Message + "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void exit_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
} }
Please help me guys. Thank you