Click here to Skip to main content
15,887,214 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to get pdf file names? Pin
OriginalGriff5-Jul-21 7:53
mveOriginalGriff5-Jul-21 7:53 
QuestionIs it possible to update content of an xml file in DropBox using DropBox API? Pin
Alex Dunlop2-Jul-21 8:51
Alex Dunlop2-Jul-21 8:51 
AnswerRe: Is it possible to update content of an xml file in DropBox using DropBox API? Pin
Dave Kreskowiak2-Jul-21 19:08
mveDave Kreskowiak2-Jul-21 19:08 
QuestionHow to add frame and Label controls at the same time by clicking a button in Xamarin? Pin
Alex Dunlop1-Jul-21 6:44
Alex Dunlop1-Jul-21 6:44 
AnswerRe: How to add frame and Label controls at the same time by clicking a button in Xamarin? Pin
Gerry Schmitz1-Jul-21 7:20
mveGerry Schmitz1-Jul-21 7:20 
GeneralRe: How to add frame and Label controls at the same time by clicking a button in Xamarin? Pin
Alex Dunlop1-Jul-21 7:27
Alex Dunlop1-Jul-21 7:27 
Questionshow the Name of ID datagridView cell0 to cell1 Pin
remiki1-Jul-21 0:21
remiki1-Jul-21 0:21 
AnswerRe: show the Name of ID datagridView cell0 to cell1 Pin
Richard Deeming1-Jul-21 0:46
mveRichard Deeming1-Jul-21 0:46 
remiki wrote:
C#
string ct = "select grade from fction inner join person on person.id= fction.id where  id ='" + dataGridView2.Rows[dvd].Cells[0].Value + "'";
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]

Beyond that, you need to update your code to store the value in the expected row, rather than adding a new row at the bottom.

You should also stop storing connections in class-level fields. Instead, create them when they're required, and wrap them in using blocks to ensure they are always disposed of properly.
C#
void gab2relik()
{
    if (dataGridView2.Rows.Count == 0) return;
    
    using (var conn = new SqlConnection(db.RXcon))
    using (var cmd = new SqlCommand("SELECT grade FROM fction INNER JOIN person ON person.id = fction.id WHERE fction.id = @ID", conn))
    {
        // TODO: Specify the correct data type and size for the parameter:
        var pID = cmd.Parameters.Add("@ID", SqlDbType.VarChar);
        
        try
        {
            conn.Open();
        }
        catch
        {
            MessageBox.Show("Erreure lors de la Connexion");
            return;
        }
        
        foreach (DataGridViewRow row in dataGridView2.Rows)
        {
            pID.Value = row.Cells[0].Value ?? DBNull.Value;
            row.Cells[2].Value = cmd.ExecuteScalar();
        }
    }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: show the Name of ID datagridView cell0 to cell1 Pin
remiki1-Jul-21 1:31
remiki1-Jul-21 1:31 
AnswerRe: show the Name of ID datagridView cell0 to cell1 Pin
OriginalGriff1-Jul-21 1:02
mveOriginalGriff1-Jul-21 1:02 
QuestionHow to count Label controls count in Xamarin? Pin
Alex Dunlop29-Jun-21 4:56
Alex Dunlop29-Jun-21 4:56 
AnswerRe: How to count Label controls count in Xamarin? Pin
Richard Deeming29-Jun-21 5:24
mveRichard Deeming29-Jun-21 5:24 
QuestionPassing parameter from one page to another Pin
Alex Dunlop28-Jun-21 6:59
Alex Dunlop28-Jun-21 6:59 
AnswerRe: Passing parameter from one page to another Pin
Gerry Schmitz28-Jun-21 7:02
mveGerry Schmitz28-Jun-21 7:02 
GeneralRe: Passing parameter from one page to another Pin
Alex Dunlop28-Jun-21 7:08
Alex Dunlop28-Jun-21 7:08 
GeneralRe: Passing parameter from one page to another Pin
Gerry Schmitz28-Jun-21 7:29
mveGerry Schmitz28-Jun-21 7:29 
GeneralRe: Passing parameter from one page to another Pin
Alex Dunlop28-Jun-21 7:34
Alex Dunlop28-Jun-21 7:34 
GeneralRe: Passing parameter from one page to another Pin
Gerry Schmitz28-Jun-21 8:02
mveGerry Schmitz28-Jun-21 8:02 
GeneralRe: Passing parameter from one page to another Pin
Richard Andrew x6428-Jun-21 14:23
professionalRichard Andrew x6428-Jun-21 14:23 
GeneralRe: Passing parameter from one page to another Pin
Richard MacCutchan28-Jun-21 21:13
mveRichard MacCutchan28-Jun-21 21:13 
GeneralRe: Passing parameter from one page to another Pin
Alex Dunlop29-Jun-21 4:53
Alex Dunlop29-Jun-21 4:53 
GeneralRe: Passing parameter from one page to another Pin
Richard MacCutchan29-Jun-21 5:44
mveRichard MacCutchan29-Jun-21 5:44 
QuestionCreate the same but in windows form C# Pin
Luis M. Rojas25-Jun-21 6:16
Luis M. Rojas25-Jun-21 6:16 
AnswerRe: Create the same but in windows form C# Pin
OriginalGriff25-Jun-21 6:23
mveOriginalGriff25-Jun-21 6:23 
QuestionDifficulty adding code to reject non numeric user inputs Pin
Member 1524886723-Jun-21 5:58
Member 1524886723-Jun-21 5:58 

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.