Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

c#.net framework

&watag

Amateur
Advanced Member
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);
}

}
}

payroll_design-jpg.368094
 
Check Data Source in
C#:
string connectionString = "Data Source=PC14358;Initial Catalog=PAYROLL_SYSTEM;Integrated Security=True";
if accessible siya. mostly full path (with port number and all) to the database ang nilalagay diyan afaik.
 
Kung meron kang SQl server Management studio. Open mo un tapos login ka. Tingnan mo properties ng database meron connection string dyan
 
Back
Top Bottom