mithun kumar

mithun kumar

  • NA
  • 21
  • 3.3k

Connection from sql server to mysql / linux server from c#

Oct 15 2016 8:44 AM
Hello,
 i have designed an desktop application designed in c# winforms application and provided connection string from sql server. i want this application to connect to  external server for php domain but it should be done using server=localhost and without port number.
 
private void button1_Click(object sender, EventArgs e)
{
string cs = @"Server=myrewards.cashier.php;Database=zapsmypr_6ten;Integrated Security=True;user Id=zapsmypr_mradmin;password=chaitu1324";
//btn_Submit Click event
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text=="" || textBox4.Text=="" || textBox5.Text=="" || textBox6.Text=="" || textBox7.Text=="" || textBox8.Text=="")
{
MessageBox.Show("Please provide data to fields");
return;
}
try
{
// Create SqlConnection
SqlConnection con = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand("INSERT INTO cashier ( fname, lname, username, password, cpass, email, cmobi, coutlet) VALUES ( @fname, @lname, @username , @password, @cpass, @email, @mobi, @coutlet)", con);
SqlCommand cm = new SqlCommand("select * from cashier where id=(select max(id)from cashier) ");
cmd.Parameters.AddWithValue("@fname", textBox1.Text);
cmd.Parameters.AddWithValue("@lname", textBox2.Text);
cmd.Parameters.AddWithValue("@username", textBox3.Text);
cmd.Parameters.AddWithValue("@password", textBox4.Text);
cmd.Parameters.AddWithValue("@cpass", textBox5.Text);
cmd.Parameters.AddWithValue("@email", textBox6.Text);
cmd.Parameters.AddWithValue("@mobi", textBox7.Text);
cmd.Parameters.AddWithValue("@coutlet", textBox8.Text);
MessageBox.Show("Your Data Saved Succesfully!!!");
con.Open();
SqlDataAdapter adapt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapt.Fill(ds);
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}