Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7490227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:34:05+00:00 2026-05-29T15:34:05+00:00

I have a table like this. Columns –> (MUSTERI, AVUKAT, HESAP (Unique)) My page

  • 0

I have a table like this. Columns –> (MUSTERI, AVUKAT, HESAP (Unique))

My page design like this.

enter image description here

Simply, first dropdown is MUSTERI, second dropdown is AVUKAT, when i click EKLE (it means ADD) button, automaticyly getting HESAP (unique) and showing on gridview.

What i want is, if any user try to add a data which they are the same HESAP, geting an error.

For example;There is a data “2M LOJİSTİJ” “ALİ ORAL” “889” in my gridview.

Someone try to add a data like “2M LOJİSTİK” “EMRA SARINÇ” “889” showing an error and don’t add to table.

My Add_Click button code is

protected void Add_Click(object sender, EventArgs e)
    {
        string strConnectionString = ConfigurationManager.ConnectionStrings["SqlServerCstr"].ConnectionString;

        SqlConnection myConnection = new SqlConnection(strConnectionString);
        myConnection.Open();


        string hesap = Label1.Text;
        string musteriadi = DropDownList1.SelectedItem.Value;
        string avukat = DropDownList2.SelectedItem.Value;

        SqlCommand cmd = new SqlCommand("INSERT INTO AVUKAT VALUES (@MUSTERI, @AVUKAT, @HESAP)", myConnection);

        cmd.Parameters.AddWithValue("@HESAP", hesap);
        cmd.Parameters.AddWithValue("@MUSTERI", musteriadi);
        cmd.Parameters.AddWithValue("@AVUKAT", avukat);
        cmd.Connection = myConnection;



        SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
        Response.Redirect(Request.Url.ToString());
        myConnection.Close();
    }

And my first dropdown MUSTERI (getting HESAP auto by this field)

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string strConnectionString = ConfigurationManager.ConnectionStrings["SqlServerCstr"].ConnectionString;

        SqlConnection myConnection = new SqlConnection(strConnectionString);
        myConnection.Open();
        string hesapNo = DropDownList1.SelectedItem.Value;

        string query = "select A.HESAP_NO from YAZ..MARDATA.S_TEKLIF A where A.MUS_K_ISIM = '" + hesapNo + "'";

        SqlCommand cmd = new SqlCommand(query, myConnection);

        if (DropDownList1.SelectedValue != "0")
        {
            Add.Enabled = true;
            Label1.Text = cmd.ExecuteScalar().ToString();
        }
        else
        {
            Add.Enabled = false;

        }
        Label1.Visible = false;
        myConnection.Close();
    }

How can i blocking insert data which already have the same HESAP?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:34:05+00:00Added an answer on May 29, 2026 at 3:34 pm

    first check HESAP is exist or not in #AVUKAT then insert new entry.

    
    protected void Add_Click(object sender, EventArgs e) 
        { 
            string strConnectionString = ConfigurationManager.ConnectionStrings["SqlServerCstr"].ConnectionString; 
    
            SqlConnection myConnection = new SqlConnection(strConnectionString); 
            myConnection.Open(); 
    
    
            string hesap = Label1.Text.Trim(); 
            string musteriadi = DropDownList1.SelectedItem.Value; 
            string avukat = DropDownList2.SelectedItem.Value; 
    
            string strsql= "SELECT * FROM AVUKAT WHERE HESAP = " + hesap;
            SqlCommand com = new SqlCommand(strsql, myConnection);
            SqlDataReader dread = com.ExecuteReader(); 
            dread.read();
            if(dread.HasRows)
            {
               myConnection.Close();
               return;
            }
    
            SqlCommand cmd = new SqlCommand("INSERT INTO AVUKAT VALUES (@MUSTERI, @AVUKAT, @HESAP)", myConnection); 
    
            cmd.Parameters.AddWithValue("@HESAP", hesap); 
            cmd.Parameters.AddWithValue("@MUSTERI", musteriadi); 
            cmd.Parameters.AddWithValue("@AVUKAT", avukat); 
            cmd.Connection = myConnection; 
    
    
    
            SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection); 
            Response.Redirect(Request.Url.ToString()); 
            myConnection.Close(); 
        } 
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table structure with columns like this [ID] [Name] [ParentId] [ParentName] The
Well, I'll say it like this. I have a table with 2 columns. The
i have an table like this with columns and values now i neeed to
I have an SQL table with columns like this: Person | Property 1 |
I have a table structure that looks like this: Columns: Account Number Service Code
I have a table with columns like this: | Country.Number | CountryName | |
Assume I have a table like this: column A(int) column B(int) 1 2 2
If i have a sql table with column like this id version subversion 1
I have a table I'd like to sort with a priority column. This column
I have a mySQL table that has a column like this: ID ----- 0352

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.