Hi ryutenkan,
Check this sample now take its reference and correct your code.
HTML
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
Select Test :
<asp:ComboBox ID="cbTest" runat="server" AutoCompleteMode="SuggestAppend">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
</asp:ComboBox><br /><br />
Enter Value :
<asp:TextBox ID="txtValue" runat="server" AutoPostBack="true" OnTextChanged="OnCheckValue" />
<asp:Label ID="lblMessage" Text="" runat="server" />
Namespaces
C#
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
VB.Net
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing
Code
C#
protected void OnCheckValue(object sender, EventArgs e)
{
string value = txtValue.Text.Trim();
string cbxValue = cbTest.SelectedValue;
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("SELECT Start FROM tblComboBox WHERE Start=@Start AND Test=@Test", con))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Start", value);
cmd.Parameters.AddWithValue("@Test", cbxValue);
con.Open();
int start = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
if (start != 0)
{
lblMessage.Text = "Already Exists";
lblMessage.ForeColor = Color.Red;
}
else
{
lblMessage.Text = "Available";
lblMessage.ForeColor = Color.Green;
}
}
}
}
VB.Net
Protected Sub OnCheckValue(ByVal sender As Object, ByVal e As EventArgs)
Dim value As String = txtValue.Text.Trim()
Dim cbxValue As String = cbTest.SelectedValue
Using con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
Using cmd As SqlCommand = New SqlCommand("SELECT Start FROM tblComboBox WHERE Start=@Start AND Test=@Test", con)
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@Start", value)
cmd.Parameters.AddWithValue("@Test", cbxValue)
con.Open()
Dim start As Integer = Convert.ToInt32(cmd.ExecuteScalar())
con.Close()
If start <> 0 Then
lblMessage.Text = "Already Exists"
lblMessage.ForeColor = Color.Red
Else
lblMessage.Text = "Available"
lblMessage.ForeColor = Color.Green
End If
End Using
End Using
End Sub
Screenshot
![](https://i.imgur.com/H3ne3Px.gif)