You are on page 1of 1

using System;

using System.Collections.Generic;
using System.Linq; using System.Web; using System.Web.UI;
using System.Web.UI.WebControls; using System.Data; using MySql.Data;
using MySql.Data.MySqlClient;
public partial class Default2 : System.Web.UI.Page
{

private string server;


private string database;
private string uid;
private string password;
private MySqlConnection connection;
private MySqlDataAdapter mySqlDataAdapter;
protected void Page_Load(object sender, EventArgs e)
{
}

protected void Button2_Click(object sender, EventArgs e)


{
server = "localhost";
database = "test1";
uid = "root";
password = "mca";

84
R.V.College of Engineering
Dept. of MCA
string connectionString;
connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";
" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
connection = new MySqlConnection(connectionString);
string query = "INSERT INTO feedback1(name,email,msg)VALUES(?name,?
email,?msg);";
MySqlCommand insertCommand = new MySqlCommand(query, connection);
insertCommand.Parameters.AddWithValue("?name", name.Text);
insertCommand.Parameters.AddWithValue("?email", email.Text);
insertCommand.Parameters.AddWithValue("?msg", msg.Text);
try
{
connection.Open();
insertCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine("exception: " + ex);
} }

Label1.Text = "inserted";
}

connection.Close();

You might also like