This way.
Database
Download the database SQL using the Link below.
Download SQL
Then you need to download MySQLConnector, for that refer
Use and connect to MySQL Database in ASP.Net Application using MySQLConnector
Stored Procedure
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `Customers_GetCustomer`(IN custId INT)
BEGIN
SELECT Name
,Country
FROM Customers
WHERE CustomerId = custId;
END$$
DELIMITER ;
HTML
Search:
<asp:TextBox ID="txtCustomerId" runat="server" Text="2" />
<asp:Button Text="Search" runat="server" OnClick="Search" />
<hr />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width = "150" />
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width = "150" />
</Columns>
</asp:GridView>
Namespaces
using System.Data;
using System.Configuration;
using MySql.Data.MySqlClient;
Code
protected void Search(object sender, EventArgs e)
{
this.GetCustomer(int.Parse(txtCustomerId.Text.Trim()));
}
private void GetCustomer(int customerId)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (MySqlConnection con = new MySqlConnection(constr))
{
using (MySqlCommand cmd = new MySqlCommand("Customers_GetCustomer", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@CustId", customerId);
using (MySqlDataAdapter sda = new MySqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}