Latest on TechNoypi.COM

Welcome to TechNoypi.COM! Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox and chat!

csharp connection to sql.

Shimz@joseph

GemsGemsGems
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
 
ano error boss?
 

Forum statistics

Threads
6,009
Messages
21,623
Members
4,652
Latest member
Oscar Vicente

User group legend

New Member Participator Helper Contributor Consultant Coach Mentor Advisor Patron Guardian Specialist Wizard Scholar Philosopher Guru Saint
Moderator Administrator
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features of our website. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock    No Thanks