Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
If put in text box username (a) and password (a) app say invalid column name "a"
 
Last line problem....some help?

 korisnikId = Int32.Parse(myCommand.ExecuteScalar().ToString());


What I have tried:

private void prijava()  
        {  
              
  
            SqlConnection myConnection = new SqlConnection(cs);  
            String command = "SELECT id FROM osobe_korisnici where korisnicko_ime = " + korisnikTextBox.Text + "";  
            myConnection.Open();  
            SqlCommand myCommand = new SqlCommand(command, myConnection);  
            
            korisnikId = Int32.Parse(myCommand.ExecuteScalar().ToString()); 
Posted
Comments
Richard MacCutchan 24-May-18 4:07am    
What is the problem?
Goran Bibic 24-May-18 4:19am    
' " + korisnikTextBox.Text + " ' "; 


This, but I solve the problem

try to solve this
Goran Bibic 24-May-18 4:19am    
Need string to label


InitializeComponent();
korisnickoImeLabel.Text = getKorisnickoIme();


What I wrong?
Query is ok


private String getKorisnickoIme()
{
SqlConnection myConnection = new SqlConnection(cs);
String value = "SELECT ime_prezime FROM osobe_korisnici WHERE id='" + korisnikId + "'";
SqlCommand cmd = new SqlCommand(value, myConnection);
myConnection.Open();
SqlDataReader rdr = cmd.ExecuteReader();
return value;

}

Result in label is
SELECT ime_prezime FROM osobe_korisnici WHERE id='10'


id is 10, but I need to write in label name and surname for user (ime_prezime)
Maciej Los 24-May-18 4:52am    
Goran, seems you don't want to learn....
We have told you several times yet that you have to use parameterized queries instead of concatenated string to avoid SQL Injection... But you still are ignoring ours instructions...
Bad practice turns you into bad programmer.
Goran Bibic 24-May-18 13:57pm    
I want to learn

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