Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Guys
can you help me with this

What I have tried:

private void button1_Click(object sender, EventArgs e)
      {
          {
              comboBox2.Enabled = true;
              string klijent = comboBox1.Text;
              CON.Open();
              string sqlquery = "SELECT Naziv FROM [Dobavljaci_" + klijent + "] WHERE NazivFirme = '" + klijent + "'";
              SqlCommand cmd = new SqlCommand(sqlquery, CON);
              SqlDataAdapter da = new SqlDataAdapter(sqlquery, CON);
              DataSet ds = new DataSet();
              da.Fill(ds);
              cmd.ExecuteNonQuery();
              comboBox2.DisplayMember = "Naziv";
              comboBox2.ValueMember = "Naziv";
              comboBox2.DataSource = ds;
          }
          {
              string klijent = comboBox1.Text;
              string sqlquery1 = "SELECT stopa FROM NKlijent WHERE NazivFirme='" + klijent + "'";
              CMD = new SqlCommand(sqlquery1, CON);
              SqlDataReader sdr1 = CMD.ExecuteReader();
              while (sdr1.Read())
              {
                  label1.Text = sdr1["stopa"].ToString();
              }
              CON.Close();
          }

On Label7 i am getting value from data base but on combobox I am getting this
System.Data.DataViewManagerListItemTypeDescriptor
Posted
Updated 29-Jun-17 21:29pm

try
comboBox2.DataSource = ds.Tables[0];


Note:
Formatting the sql Query string is vulnerable to SQL Injection[^] attacks
always use Parameterized queries to prevent SQL Injection Attacks in SQL Server[^]
 
Share this answer
 
v2
Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900