2005-02-08, 04:59 AM
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">string commstr = "UPDATE VideoInfo SET ";
OleDbConnection conn = new OleDbConnection(connstring);
OleDbCommand command;
bool update = false;
if(video.Description != "")
{
commstr += "Description=@Description";
update = true;
}
if(video.Title != "")
{
commstr += (update?", ":"")+ "Title=@Title";
update = true;
}
if(video.Subtitle != "")
{
commstr += (update?", ":"")+ "Subtitle=@Subtitle";
update = true;
}
commstr += " WHERE Filename=@Filename";
command = new OleDbCommand(commstr,conn);
if(commstr.IndexOf("@Filename") > 0)
command.Parameters.Add("@Filename",video.Filename);
if(commstr.IndexOf("@Description")>0)
{
command.Parameters.Add("@Description",video.Description);
}
if(commstr.IndexOf("@Title")>0)
{
command.Parameters.Add("@Title",video.Title);
}
if(commstr.IndexOf("@Subtitle")>0){
command.Parameters.Add("@Subtitle",video.Subtitle);
}
if(update)
{
conn.Open();
command.ExecuteNonQuery();
conn.Close();
}[/QUOTE]
ok the above code runs without a problem, no exceptions are throw (i put logger.verbose() above and below the command.executenonquery() and it runs fine. just nothing is updated.
if i use something like
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">commstr += "Description=\"This is a description\"";[/QUOTE]
instead of "Description=@Description" for each desc,title,subtile, it runs fine and things are updated, even if i leave:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">Filename=@Filename, and use the Parameter.Add("@Filename",video.filename).[/QUOTE]
ive used similar code before, just to update a byte in a database with no problems ie:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">OleDbConnection conn = new OleDbConnection(connstring);
OleDbCommand command = new OleDbCommand("UPDATE VideoInfo SET Seen = '"+(seen? 1 : 0)+"' WHERE Filename=@Filename",conn);
command.Parameters.Add("@Filename",filename);
conn.Open();
command.ExecuteNonQuery();
conn.Close();
success = true;[/QUOTE]
of course im setting it without a parameter, but ive also used:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">OleDbConnection conn = new OleDbConnection(connstring);
OleDbCommand command = new OleDbCommand("UPDATE VideoInfo SET Filename=@NewName WHERE Filename=@OldName",conn);
command.Parameters.Add("@NewName",newname);
command.Parameters.Add("@OldName",oldname);
conn.Open();
command.ExecuteNonQuery();
conn.Close();[/QUOTE]
so anyone see my error, this is driving me nuts. its got to be something stupid, also i know the first code isnt the best way to do it, but first time using databases, and thats the only way i could figure out how to create the command, with only the strings of length > 0. any help would greatly be appreciate, this is really really really driving me nuts, at screaming at computer stage
TIA
reven.
OleDbConnection conn = new OleDbConnection(connstring);
OleDbCommand command;
bool update = false;
if(video.Description != "")
{
commstr += "Description=@Description";
update = true;
}
if(video.Title != "")
{
commstr += (update?", ":"")+ "Title=@Title";
update = true;
}
if(video.Subtitle != "")
{
commstr += (update?", ":"")+ "Subtitle=@Subtitle";
update = true;
}
commstr += " WHERE Filename=@Filename";
command = new OleDbCommand(commstr,conn);
if(commstr.IndexOf("@Filename") > 0)
command.Parameters.Add("@Filename",video.Filename);
if(commstr.IndexOf("@Description")>0)
{
command.Parameters.Add("@Description",video.Description);
}
if(commstr.IndexOf("@Title")>0)
{
command.Parameters.Add("@Title",video.Title);
}
if(commstr.IndexOf("@Subtitle")>0){
command.Parameters.Add("@Subtitle",video.Subtitle);
}
if(update)
{
conn.Open();
command.ExecuteNonQuery();
conn.Close();
}[/QUOTE]
ok the above code runs without a problem, no exceptions are throw (i put logger.verbose() above and below the command.executenonquery() and it runs fine. just nothing is updated.
if i use something like
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">commstr += "Description=\"This is a description\"";[/QUOTE]
instead of "Description=@Description" for each desc,title,subtile, it runs fine and things are updated, even if i leave:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">Filename=@Filename, and use the Parameter.Add("@Filename",video.filename).[/QUOTE]
ive used similar code before, just to update a byte in a database with no problems ie:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">OleDbConnection conn = new OleDbConnection(connstring);
OleDbCommand command = new OleDbCommand("UPDATE VideoInfo SET Seen = '"+(seen? 1 : 0)+"' WHERE Filename=@Filename",conn);
command.Parameters.Add("@Filename",filename);
conn.Open();
command.ExecuteNonQuery();
conn.Close();
success = true;[/QUOTE]
of course im setting it without a parameter, but ive also used:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">OleDbConnection conn = new OleDbConnection(connstring);
OleDbCommand command = new OleDbCommand("UPDATE VideoInfo SET Filename=@NewName WHERE Filename=@OldName",conn);
command.Parameters.Add("@NewName",newname);
command.Parameters.Add("@OldName",oldname);
conn.Open();
command.ExecuteNonQuery();
conn.Close();[/QUOTE]
so anyone see my error, this is driving me nuts. its got to be something stupid, also i know the first code isnt the best way to do it, but first time using databases, and thats the only way i could figure out how to create the command, with only the strings of length > 0. any help would greatly be appreciate, this is really really really driving me nuts, at screaming at computer stage
TIA
reven.