SQL Structure :
Column Name |
Column Data Type |
ID |
INT |
Name |
nvarchar(100) |
Advance |
INT |
C# Coding :
1 TextBox for Searching the ID
1 Button for Validating the Search Box
1 Label for showing message
<asp:TextBox ID="SearchBox" runat="server"></asp:TextBox>
<asp:Button ID="ValidationButton" runat="server" Text="Button"
onclick="ValidationButton_Click" />
<asp:Label ID="MsgLabel" runat="server" Text=""></asp:Label>
protected void ValidationButton_Click(object sender, EventArgs e)
{
int check = CheckIfRecordExist();
if (check > 0)
{
MsgLabel.Text = "Record Already exist";
}
else
{
// .... pay him advance salary
}
}
public int CheckIfRecordExist()
{
string query = "Select * from tblAdvanceSalary WHERE ID = @ID";
var comm = new SqlCommand(query, _connectionStringVariable);
comm.Parameters.AddWithValue("@ID", SearchBox.Text);
var dt = new DataTable();
Con.Open();
var da = new SqlDataAdapter { SelectCommand = comm };
da.Fill(dt);
int IsExist = dt.Rows.Count > 0 ? 1 : 0;
Con.Close();
return IsExist;
}