Click here to Skip to main content
15,907,493 members
Home / Discussions / Database
   

Database

 
Generalhelp in undertsnading the joins Pin
satishrg19-May-05 5:31
satishrg19-May-05 5:31 
GeneralRe: help in undertsnading the joins Pin
Colin Angus Mackay19-May-05 6:39
Colin Angus Mackay19-May-05 6:39 
GeneralRe: help in undertsnading the joins Pin
satishrg19-May-05 7:58
satishrg19-May-05 7:58 
GeneralRe: help in undertsnading the joins Pin
Colin Angus Mackay19-May-05 12:34
Colin Angus Mackay19-May-05 12:34 
Questionproblem with update a row? Pin
Sasuko19-May-05 5:10
Sasuko19-May-05 5:10 
AnswerRe: problem with update a row? Pin
Colin Angus Mackay19-May-05 5:31
Colin Angus Mackay19-May-05 5:31 
GeneralRe: problem with update a row? Pin
Sasuko19-May-05 11:41
Sasuko19-May-05 11:41 
AnswerRe: problem with update a row? Pin
Luis Alonso Ramos19-May-05 14:09
Luis Alonso Ramos19-May-05 14:09 
Colin just told you and I had told you before in some threads below: use parametized queries. You don't have to think about how to format parameters, and also is more secure. Try this code:
string sql = "UPDATE TmyTable SET Title=@Title, Text=@Text," +
    " Left=@Left, Top=@Top, Color=@Color WHERE ID=@ID";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@Title", labelTitle.Text);
cmd.Parameters.Add("@Text", TextBox1.Text);
cmd.Parameters.Add("@Left", this.Left);
cmd.Parameters.Add("@Top", this.Top);
cmd.Parameters.Add("@Color", panelColor.BackColor.ToArgg());
cmd.Parameters.Add("@ID", id);
cmd.ExecuteNonQuery();
Do you see how you don't have to think about enclosing strings in single quotes or if day or month goes first in a date?

The above code is for SQL Server, which uses named parameters. OleDb* classes (Access for example) use unnamed parameters. In the query you just put a question mark, and add parameters to the Parameters collection in the order they appear in the query.
string sql = "UPDATE TmyTable SET Title= ?, Text= ?," +
    " Left=@ ?, Top= ?, Color= ? WHERE ID= ?";
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.Parameters.Add("@Title", labelTitle.Text);  // Parameter name really doesn't matter.
cmd.Parameters.Add("@Text", TextBox1.Text);
cmd.Parameters.Add("@Left", this.Left);
cmd.Parameters.Add("@Top", this.Top);
cmd.Parameters.Add("@Color", panelColor.BackColor.ToArgg());
cmd.Parameters.Add("@ID", id);
cmd.ExecuteNonQuery();
Oracle also uses named parameters like SQL Server. You have to prepend a colon in the query like in UPDATE TmyTable SET Title=:title, but not when adding the parameter: cmd.Parameters.Add("title", labelTitle.Text). If you are using some other database (mySql for example), search the docs, it's possible and parametized queries will make your life much easier (really!!)

-- LuisR



Luis Alonso Ramos
Intelectix - Chihuahua, Mexico

Not much here: My CP Blog!

GeneralRe: problem with update a row? Pin
Sasuko20-May-05 2:57
Sasuko20-May-05 2:57 
GeneralRe: problem with update a row? Pin
Sasuko20-May-05 4:19
Sasuko20-May-05 4:19 
GeneralRe: problem with update a row? Pin
Luis Alonso Ramos20-May-05 4:58
Luis Alonso Ramos20-May-05 4:58 
GeneralRe: problem with update a row? Pin
Sasuko20-May-05 5:00
Sasuko20-May-05 5:00 
GeneralRe: problem with update a row? Pin
Luis Alonso Ramos20-May-05 5:11
Luis Alonso Ramos20-May-05 5:11 
GeneralRe: problem with update a row? Pin
Sasuko20-May-05 5:21
Sasuko20-May-05 5:21 
GeneralRe: problem with update a row? Pin
Blue_Boy24-May-05 4:01
Blue_Boy24-May-05 4:01 
Generalpicture inserting.please help me! Pin
rohollahabadan19-May-05 2:20
rohollahabadan19-May-05 2:20 
GeneralRe: picture inserting.please help me! Pin
NewSilence21-May-05 12:11
NewSilence21-May-05 12:11 
GeneralRe: picture inserting.please help me! Pin
rohollahabadan22-May-05 21:23
rohollahabadan22-May-05 21:23 
Generalplease help me .please please.... Pin
rohollahabadan19-May-05 2:12
rohollahabadan19-May-05 2:12 
GeneralRe: please help me .please please.... Pin
RChin19-May-05 3:48
RChin19-May-05 3:48 
GeneralThe stored procedure .... Pin
rohollahabadan20-May-05 23:19
rohollahabadan20-May-05 23:19 
GeneralRe: The stored procedure .... Pin
RChin22-May-05 23:13
RChin22-May-05 23:13 
Generalto me rchin. Pin
rohollahabadan22-May-05 21:26
rohollahabadan22-May-05 21:26 
GeneralRe: to me rchin. Pin
RChin22-May-05 23:15
RChin22-May-05 23:15 
GeneralRestore Database from MDF file without LDF Pin
18-May-05 20:39
suss18-May-05 20:39 

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.