Click here to Skip to main content
15,881,092 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Pin
Eddy Vluggen4-Aug-15 3:18
professionalEddy Vluggen4-Aug-15 3:18 
Question#SNMP Calculate Bandwidth Utilization Pin
LeHuuTien3-Aug-15 22:07
LeHuuTien3-Aug-15 22:07 
AnswerRe: #SNMP Calculate Bandwidth Utilization Pin
Guerrilla Coder3-Aug-15 22:49
Guerrilla Coder3-Aug-15 22:49 
GeneralRe: #SNMP Calculate Bandwidth Utilization Pin
LeHuuTien4-Aug-15 2:28
LeHuuTien4-Aug-15 2:28 
Questioni am not getting my desired results Pin
Dark Commet3-Aug-15 0:18
Dark Commet3-Aug-15 0:18 
AnswerRe: i am not getting my desired results Pin
Saundarya Pradhan3-Aug-15 0:43
Saundarya Pradhan3-Aug-15 0:43 
AnswerRe: i am not getting my desired results Pin
OriginalGriff3-Aug-15 0:47
mveOriginalGriff3-Aug-15 0:47 
AnswerRe: i am not getting my desired results Pin
Nicholas Marty3-Aug-15 0:58
professionalNicholas Marty3-Aug-15 0:58 
First: Don't use string concatenation to build your SQL queries!

A few more issues:
- "usernametxtbox" and "passwordtxtbox probably results in something like "System.Windows.Forms.TextBox" instead of the actual value. Make sure you access the "Text" property of those objects to get the value stored inside them
- There is no need for a DataTable or an SqlDataAdapter.
- Make sure you dispose of the Sql-objects if you're done (else you might run into memory leaks)

Go with something like this (using "using" will make sure the objects are disposed)
C#
using(var con = new SqlConnection(@"Data Source=SAJJAD-PC;Initial Catalog=hotel;Integrated Security=True;") {
   con.Open();
   using(var cmd = con.CreateCommand()) {
      cmd.CommandText="SELECT COUNT(*) FROM login WHERE username=@username AND password=@password";
      // Adjust the size of the column according to the database field size. I just use 50 as an example
      cmd.Parameters.Add("@username", SqlDbType.Varchar, 50).Value = usernametxtbox.Text; 
      cmd.Parameters.Add("@password", SqlDbType.Varchar, 50).Value = passwordtxtbox.Text;
      var result = (int)cmd.ExecuteScalar();
      if(result==1) {
         // Username and Password match found
      } else {
         // No match found
      }
   }
}

AnswerRe: i am not getting my desired results Pin
HUKUMAT RAY KUMAWAT3-Aug-15 18:37
HUKUMAT RAY KUMAWAT3-Aug-15 18:37 
QuestionRe: i am not getting my desired results Pin
Richard MacCutchan3-Aug-15 21:03
mveRichard MacCutchan3-Aug-15 21:03 
GeneralRe: i am not getting my desired results Pin
Eddy Vluggen3-Aug-15 21:17
professionalEddy Vluggen3-Aug-15 21:17 
GeneralRe: i am not getting my desired results Pin
Richard MacCutchan3-Aug-15 22:13
mveRichard MacCutchan3-Aug-15 22:13 
GeneralRe: i am not getting my desired results Pin
OriginalGriff3-Aug-15 22:49
mveOriginalGriff3-Aug-15 22:49 
GeneralRe: i am not getting my desired results Pin
Eddy Vluggen3-Aug-15 22:56
professionalEddy Vluggen3-Aug-15 22:56 
GeneralRe: i am not getting my desired results Pin
OriginalGriff3-Aug-15 23:11
mveOriginalGriff3-Aug-15 23:11 
GeneralRe: i am not getting my desired results Pin
Eddy Vluggen3-Aug-15 23:27
professionalEddy Vluggen3-Aug-15 23:27 
GeneralRe: i am not getting my desired results Pin
Richard MacCutchan3-Aug-15 23:49
mveRichard MacCutchan3-Aug-15 23:49 
GeneralRe: i am not getting my desired results Pin
Eddy Vluggen4-Aug-15 0:05
professionalEddy Vluggen4-Aug-15 0:05 
GeneralRe: i am not getting my desired results Pin
Richard MacCutchan4-Aug-15 0:11
mveRichard MacCutchan4-Aug-15 0:11 
GeneralRe: i am not getting my desired results Pin
Eddy Vluggen4-Aug-15 0:19
professionalEddy Vluggen4-Aug-15 0:19 
GeneralRe: i am not getting my desired results Pin
Richard MacCutchan4-Aug-15 0:27
mveRichard MacCutchan4-Aug-15 0:27 
GeneralRe: i am not getting my desired results Pin
Eddy Vluggen4-Aug-15 0:46
professionalEddy Vluggen4-Aug-15 0:46 
GeneralRe: i am not getting my desired results Pin
OriginalGriff4-Aug-15 2:36
mveOriginalGriff4-Aug-15 2:36 
GeneralRe: i am not getting my desired results Pin
Richard MacCutchan4-Aug-15 2:46
mveRichard MacCutchan4-Aug-15 2:46 
GeneralRe: i am not getting my desired results Pin
Richard MacCutchan3-Aug-15 23:50
mveRichard MacCutchan3-Aug-15 23:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.