- Messages
- 115
- Reaction score
- 0
- Points
- 26
Phelp please.
Baka may makatulong sa connection ayaw mag connect sa sql. thank you
private void button1_Click(object sender, EventArgs e)
{
//..
string connectionString = "Data Source=PC14358;Initial Catalog=PAYROLL_SYSTEM;Integrated Security=True";
using(SqlConnection connection = new SqlConnection(connectionString))
{
try
{
connection.Open();
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_num.Text}'";//','{e_name.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})";
using (SqlCommand command = new SqlCommand(query, connection))
{
int rowsAffected = command.ExecuteNonQuery();
if (rowsAffected > 0)
{
MessageBox.Show("Record Saved", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Failed to save Data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
} catch(Exception ex)
{
MessageBox.Show("Error: ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Baka may makatulong sa connection ayaw mag connect sa sql. thank you
private void button1_Click(object sender, EventArgs e)
{
//..
string connectionString = "Data Source=PC14358;Initial Catalog=PAYROLL_SYSTEM;Integrated Security=True";
using(SqlConnection connection = new SqlConnection(connectionString))
{
try
{
connection.Open();
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_num.Text}'";//','{e_name.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})";
using (SqlCommand command = new SqlCommand(query, connection))
{
int rowsAffected = command.ExecuteNonQuery();
if (rowsAffected > 0)
{
MessageBox.Show("Record Saved", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Failed to save Data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
} catch(Exception ex)
{
MessageBox.Show("Error: ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}