Click here to Skip to main content
15,893,722 members
Home / Discussions / C#
   

C#

 
GeneralRe: Windows Forms Applications Pin
Zeyad Jalil19-Mar-12 23:22
professionalZeyad Jalil19-Mar-12 23:22 
AnswerRe: Windows Forms Applications Pin
JF201519-Mar-12 23:31
JF201519-Mar-12 23:31 
AnswerRe: Windows Forms Applications Pin
Pete O'Hanlon20-Mar-12 0:09
mvePete O'Hanlon20-Mar-12 0:09 
GeneralRe: Windows Forms Applications Pin
Zeyad Jalil20-Mar-12 0:26
professionalZeyad Jalil20-Mar-12 0:26 
AnswerRe: Windows Forms Applications Pin
Comfizzy20-Mar-12 4:38
Comfizzy20-Mar-12 4:38 
Questionhow to retrieve data from mysql database and display it into textbox in c# Pin
Xonel19-Mar-12 21:24
Xonel19-Mar-12 21:24 
AnswerRe: how to retrieve data from mysql database and display it into textbox in c# Pin
Abhinav S19-Mar-12 22:13
Abhinav S19-Mar-12 22:13 
AnswerRe: how to retrieve data from mysql database and display it into textbox in c# Pin
OriginalGriff19-Mar-12 22:40
mveOriginalGriff19-Mar-12 22:40 
There are two important things to do here:
1) Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead:
C#
string sql = "SELECT * FROM addmember WHERE Member_ID = @ID;";
MySqlDataAdapter da = new MySqlDataAdapter(sql, myconn);
da.SelectCommand.Parameters.AddWithValue("@ID", input);

2) Don't use "*" as the column list in an sql command - particularly if you are going to use numeric indexes. Not only do they make your code liable to fail if the external database is changed, but the order in which SQL returns columns is not defined - when you specify "*" as the columns list SQL is at liberty to return them in any order it desires. Normally it returns them in definition order - but it doesn't have to, and there is no guarantee that future versions will do so. Name your columns in the SELECT (preferred, as it reduces the data returned to just the columns you want), and / or use names for the DataRow index.

Implementing these may solve your problem, but you also should not add an empty sting onto the dataRow - it looks silly and is unnecessary. cast it to a string instead:
C#
foreach (DataRow dr in dt.Rows)
   {
   string iD = (string) dr["iD"];
   if ((string) dr["iD"] == input)
      {
      txtFirstName.Text = (string) dr["FirstName"];
      break;
   }
}

Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

GeneralRe: how to retrieve data from mysql database and display it into textbox in c# Pin
Xonel20-Mar-12 0:53
Xonel20-Mar-12 0:53 
GeneralRe: how to retrieve data from mysql database and display it into textbox in c# Pin
OriginalGriff20-Mar-12 1:14
mveOriginalGriff20-Mar-12 1:14 
AnswerRe: how to retrieve data from mysql database and display it into textbox in c# Pin
PIEBALDconsult20-Mar-12 3:42
mvePIEBALDconsult20-Mar-12 3:42 
QuestionHymns Pin
Bollyjames19-Mar-12 19:03
Bollyjames19-Mar-12 19:03 
AnswerRe: Hymns Pin
Mycroft Holmes19-Mar-12 20:52
professionalMycroft Holmes19-Mar-12 20:52 
AnswerRe: Hymns Pin
Abhinav S19-Mar-12 22:22
Abhinav S19-Mar-12 22:22 
AnswerRe: Hymns Pin
DaveyM6920-Mar-12 1:08
professionalDaveyM6920-Mar-12 1:08 
QuestionCAD system design Pin
Bollyjames19-Mar-12 18:58
Bollyjames19-Mar-12 18:58 
AnswerRe: CAD system design Pin
Alan Balkany21-Mar-12 4:54
Alan Balkany21-Mar-12 4:54 
Questioni have a global mouse hook working but.. Pin
gmes2919-Mar-12 14:07
gmes2919-Mar-12 14:07 
AnswerRe: i have a global mouse hook working but.. Pin
Dave Kreskowiak19-Mar-12 16:08
mveDave Kreskowiak19-Mar-12 16:08 
GeneralRe: i have a global mouse hook working but.. Pin
gmes2920-Mar-12 0:59
gmes2920-Mar-12 0:59 
Questionsame enumeration, different results? Pin
CCodeNewbie19-Mar-12 12:15
CCodeNewbie19-Mar-12 12:15 
AnswerRe: same enumeration, different results? Pin
PIEBALDconsult19-Mar-12 12:31
mvePIEBALDconsult19-Mar-12 12:31 
GeneralRe: same enumeration, different results? Pin
CCodeNewbie19-Mar-12 12:39
CCodeNewbie19-Mar-12 12:39 
GeneralRe: same enumeration, different results? Pin
PIEBALDconsult19-Mar-12 12:43
mvePIEBALDconsult19-Mar-12 12:43 
GeneralRe: same enumeration, different results? Pin
CCodeNewbie19-Mar-12 12:50
CCodeNewbie19-Mar-12 12: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.