Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre28-Apr-15 7:27
professionalSascha Lefèvre28-Apr-15 7:27 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell28-Apr-15 9:00
Norris Chappell28-Apr-15 9:00 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Norris Chappell28-Apr-15 10:12
Norris Chappell28-Apr-15 10:12 
GeneralRe: How to compare a sql server table field with a csv field and display what is not in the sql table. Pin
Sascha Lefèvre28-Apr-15 10:16
professionalSascha Lefèvre28-Apr-15 10:16 
Questioninserire il dato nel database access (senza generare uno nuovo) Pin
Member 1161509923-Apr-15 3:22
Member 1161509923-Apr-15 3:22 
AnswerRe: inserire il dato nel database access (senza generare uno nuovo) Pin
Pete O'Hanlon23-Apr-15 3:24
mvePete O'Hanlon23-Apr-15 3:24 
GeneralRe: inserire il dato nel database access (senza generare uno nuovo) Pin
Member 1161509924-Apr-15 1:01
Member 1161509924-Apr-15 1:01 
AnswerRe: inserire il dato nel database access (senza generare uno nuovo) Pin
Richard Deeming23-Apr-15 9:32
mveRichard Deeming23-Apr-15 9:32 
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

To update the same row, you will need to retrieve and store the ID from the new row, and then issue an UPDATE statement:
C#
private int? _id;

private void btnentrata_Click(object sender, EventArgs e)
{
    using (OleDbConnection cn = DataBase.CreaConnessione())
    using (OleDbCommand cmd = cn.CreateCommand())
    {
        cmd.CommandText = "INSERT INTO operai (cognome, nome, entrata) VALUES (?, ?, ?)";
        cmd.CommandType = CommandType.Text;

        // OleDbCommand doesn't use named parameters, so the names don't matter here; only the order.
        cmd.Parameters.AddWithValue("p0", txtcognome.Text);
        cmd.Parameters.AddWithValue("p1", txtnome.Text);
        cmd.Parameters.AddWithValue("p2", DateTime.Now);

        cn.Open();
        cmd.ExecuteNonQuery();
        
        cmd.CommandText = "SELECT @@IDENTITY";
        cmd.Parameters.Clear();
        _id = (int)cmd.ExecuteScalar();
    }
}

private void btuscita_Click(object sender, EventArgs e)
{
    if (_id == null)
    {
        throw new InvalidOperationException("Row not created!");
    }
    
    using (OleDbConnection cn = DataBase.CreaConnessione())
    using (OleDbCommand cmd = cn.CreateCommand())
    {
        cmd.CommandText = "UPDATE operai SET uscita = ? WHERE ID = ?";
        cmd.CommandType = CommandType.Text;

        // OleDbCommand doesn't use named parameters, so the names don't matter here; only the order.
        cmd.Parameters.AddWithValue("p0", DateTime.Now);
        cmd.Parameters.AddWithValue("p1", _id);

        cn.Open();
        cmd.ExecuteNonQuery();
    }
}




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


QuestionUnable to load DLL "dllforvc.dll": The specified module could not be found. (Exception from HRESULT: 0x8007007E). Pin
Member 1159873923-Apr-15 1:27
Member 1159873923-Apr-15 1:27 
AnswerRe: Unable to load DLL "dllforvc.dll": The specified module could not be found. (Exception from HRESULT: 0x8007007E). Pin
Pete O'Hanlon23-Apr-15 1:37
mvePete O'Hanlon23-Apr-15 1:37 
GeneralRe: Unable to load DLL "dllforvc.dll": The specified module could not be found. (Exception from HRESULT: 0x8007007E). Pin
Member 1159873923-Apr-15 22:36
Member 1159873923-Apr-15 22:36 
GeneralRe: Unable to load DLL "dllforvc.dll": The specified module could not be found. (Exception from HRESULT: 0x8007007E). Pin
Pete O'Hanlon23-Apr-15 22:58
mvePete O'Hanlon23-Apr-15 22:58 
Questionconvert code form C# 2008 to C# 2005 have DataClass ? Pin
Member 245846722-Apr-15 20:32
Member 245846722-Apr-15 20:32 
AnswerRe: convert code form C# 2008 to C# 2005 have DataClass ? Pin
OriginalGriff22-Apr-15 21:42
mveOriginalGriff22-Apr-15 21:42 
AnswerRe: convert code form C# 2008 to C# 2005 have DataClass ? Pin
Richard Deeming23-Apr-15 1:55
mveRichard Deeming23-Apr-15 1:55 
AnswerRe: convert code form C# 2008 to C# 2005 have DataClass ? Pin
Member 245846723-Apr-15 18:10
Member 245846723-Apr-15 18:10 
Questiontreeview node selection always return first Node of Tree, instead of selected one Pin
anupam_unique22-Apr-15 7:00
anupam_unique22-Apr-15 7:00 
QuestionHow to spoof ip in webBrowser control Pin
hapiten22-Apr-15 5:52
hapiten22-Apr-15 5:52 
AnswerRe: How to change ip in webBrowser control Pin
Richard MacCutchan22-Apr-15 6:35
mveRichard MacCutchan22-Apr-15 6:35 
GeneralRe: How to change ip in webBrowser control Pin
hapiten22-Apr-15 6:55
hapiten22-Apr-15 6:55 
GeneralRe: How to change ip in webBrowser control Pin
Richard MacCutchan22-Apr-15 7:03
mveRichard MacCutchan22-Apr-15 7:03 
AnswerRe: How to spoof ip in webBrowser control Pin
Eddy Vluggen22-Apr-15 9:01
professionalEddy Vluggen22-Apr-15 9:01 
QuestionWinForm Database is locked SQLite Pin
DPaul199422-Apr-15 4:20
DPaul199422-Apr-15 4:20 
AnswerRe: WinForm Database is locked SQLite Pin
Simon_Whale22-Apr-15 4:29
Simon_Whale22-Apr-15 4:29 
AnswerRe: WinForm Database is locked SQLite Pin
Sascha Lefèvre22-Apr-15 4:42
professionalSascha Lefèvre22-Apr-15 4:42 

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.