NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 76 77 78 79 80 … 93 Next »
updating a database

 
  • 0 Vote(s) - 0 Average
updating a database
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#1
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 &quot;Description=@Description&quot; 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 &gt; 0. any help would greatly be appreciate, this is really really really driving me nuts, at screaming at computer stage [Image: smile.gif]

TIA
reven.
KingArgyle
Offline

Posting Freak

Posts: 1,271
Threads: 95
Joined: Nov 2004
#2
2005-02-08, 06:02 AM
Reven, this thread might help you:

http://gbpvr.com/cgi-bin/ikonboard.cgi?a...f=4;t=2848

Believe me I've been in your situation with OLE DB.
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#3
2005-02-08, 08:19 AM
thanks KingArgyle , i read those posts and after 2 hours of yelling all sorts of extremely colourful words to the computer it works.  using this code:
<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);
conn.Open();

System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand();

if(video.Poster == null)
{
command.CommandText = "UPDATE VideoInfo SET Title=?, Subtitle=?, Description=?, Runtime=?, Genres=?, Certification=? WHERE Filename=?";
command.Connection = conn;
command.Prepare();

command.Parameters.Add("Title", System.Data.OleDb.OleDbType.VarChar,255);
command.Parameters.Add("Subtitle", System.Data.OleDb.OleDbType.VarChar,255);
command.Parameters.Add("Description", System.Data.OleDb.OleDbType.VarChar);
command.Parameters.Add("Runtime", System.Data.OleDb.OleDbType.VarChar,255);
command.Parameters.Add("Genres", System.Data.OleDb.OleDbType.VarChar,255);
command.Parameters.Add("Certification", System.Data.OleDb.OleDbType.VarChar,255);
command.Parameters.Add("Filename", System.Data.OleDb.OleDbType.VarChar);

command.Parameters[0].Value = video.Title;
command.Parameters[1].Value = video.Subtitle;
command.Parameters[2].Value = video.Description;
command.Parameters[3].Value = video.Runtime;
command.Parameters[4].Value = video.Genres;
command.Parameters[5].Value = video.Certification;
command.Parameters[6].Value = video.Filename;

command.ExecuteNonQuery();
}
conn.Close(); [/QUOTE]
also thanks to jasonf who posted the post that helped me out.  god i hate database.:angry:



« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  Delete recordings from database but not from disk? spinnaker 8 3,925 2013-10-26, 10:51 PM
Last Post: spinnaker
  trying to fake npvr database for unit tests reven 3 2,302 2013-05-20, 08:53 AM
Last Post: reven
  updating EPG reven 3 2,071 2012-11-30, 09:05 PM
Last Post: reven
  Merged database queries mvallevand 4 2,164 2011-06-26, 09:56 PM
Last Post: mvallevand
  NPVR database questions mvallevand 25 10,002 2011-01-06, 12:58 AM
Last Post: jksmurf
  NPVR database - why so stringy with the fields?? :0) carpeVideo 4 2,117 2010-09-21, 01:48 AM
Last Post: sub
  NPVR Database connection ralphy 4 2,573 2010-09-15, 12:09 AM
Last Post: sub
  Updating images scb147 11 4,528 2010-07-30, 06:11 PM
Last Post: scb147
  How can I reset the Music plugin's database? mkenyon2 1 1,952 2009-10-15, 06:43 PM
Last Post: psycik
  SheduleRecording() locks database cb123 3 2,592 2009-02-14, 06:33 PM
Last Post: sub

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode