Mysql Storedprocedure OR Query
If we search to the database one condition or two condition set but now i am using or condition any one condition correct display the result using Mysql Storedprocedure in Asp.Net C#.
DEMO
MySql Stored Procedure
Html Coding
C# CODING
Next - Add database and stored procedure in the Codebehind file
If we search to the database one condition or two condition set but now i am using or condition any one condition correct display the result using Mysql Storedprocedure in Asp.Net C#.
DEMO
MySql Stored Procedure
CREATE
DEFINER=`root`@`localhost` PROCEDURE `sp_select_Date`(In vfromdate varchar(15),In vusername varchar(15))
BEGIN
select
* from `userinformation` where fromdate=vfromdate or UserName=vusername;
END
Html Coding
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<table><tr><td>Username</td><td>
<asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>
</td></tr>
<tr><td>Date</td><td>
<asp:TextBox ID="txtDate" TextMode="Date" runat="server"></asp:TextBox>
</td></tr>
<tr><td></td><td>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Login" style="height: 26px" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Reset" />
</td></tr>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</table>
</div>
</form>
</body>
</html>
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.MySqlClient;
public partial class Login : System.Web.UI.Page
{
MySqlConnection con = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbc"].ToString());
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
MySqlCommand cmd = new MySqlCommand("sp_select_Date",
con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@vfromdate",
txtDate.Text);
cmd.Parameters.AddWithValue("@vusername",txtUsername.Text);
MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds);
if(ds.Tables[0].Rows.Count>0)
{
GridView1.DataSource
=ds;
GridView1.DataBind();
con.Close();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
txtDate.Text = string.Empty;
txtUsername.Text = string.Empty;
GridView1.DataSource = null;
GridView1.DataBind();
}
}
Add - New Web form - Required textbox and label and gridview add
Next - Cerate Mysql Stored Procedure for OR Query
Next - Add database and stored procedure in the Codebehind file
Awesome article on Mysql Storedprocedure
ReplyDelete