NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 25 26 27 28 29 … 93 Next »
Starting out with vb.net and sqlite3...

 
  • 0 Vote(s) - 0 Average
Starting out with vb.net and sqlite3...
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,789
Threads: 769
Joined: Nov 2003
#11
2008-03-21, 10:21 PM
zehd Wrote:In the above example, I use a generic .getvalue that will take whatever type the data is and then it goes into a string. I suppsoe I could start to use specific datatypes. I know that VB6 is notorious for being slow when using variants. What do you all suggest?
I prefer to stick with real data types.

Quote:Also, I'd like to pump the results into an array. Is it correct to grab each column of each line, like this and add to array, or is there a way to get the query results already in a two dimensional array...
You could do something like this...

Declare some class to hold the various attributes:

Code:
public class Genre
{
   public int oid;
   public string genreName;
   public unsigned int argb;
}

then create a list and populare a instance of that class each time around the loop...
Code:
ArrayList genreList = new ArrayList();

    // load list of genre codes
    DbCommand command = dbProviderFactory.CreateCommand();
    command.Connection = connection;
    command.CommandText = "SELECT * from GENRE";    
    DbDataReader dataReader = command.ExecuteReader();
    while (dataReader.Read())
    {
        // create new instance
        Genre myGenre= new Genre();

        // load object from database settings        
        myGenre.oid = dataReader.GetInt32(dataReader.GetOrdinal("oid"));
        myGenre.name = dataReader.GetString(dataReader.GetOrdinal("genre_name"));
        .... etc

        // add object to list
        genreList.Add(myGenre);
    }
    dataReader.Close();

At the end of this you'd have a list of all the genre objects in the database.
zehd
Offline

Posting Freak

Posts: 5,119
Threads: 249
Joined: Feb 2006
#12
2008-03-21, 10:38 PM
sub Wrote:I prefer to stick with real data types.

You could do something like this...

Declare some class to hold the various attributes:

Code:
public class Genre
{
   public int oid;
   public string genreName;
   public unsigned int argb;
}

then create a list and populare a instance of that class each time around the loop...
Code:
ArrayList genreList = new ArrayList();

    // load list of genre codes
    DbCommand command = dbProviderFactory.CreateCommand();
    command.Connection = connection;
    command.CommandText = "SELECT * from GENRE";    
    DbDataReader dataReader = command.ExecuteReader();
    while (dataReader.Read())
    {
        // create new instance
        Genre myGenre= new Genre();

        // load object from database settings        
        myGenre.oid = dataReader.GetInt32(dataReader.GetOrdinal("oid"));
        myGenre.name = dataReader.GetString(dataReader.GetOrdinal("genre_name"));
        .... etc

        // add object to list
        genreList.Add(myGenre);
    }
    dataReader.Close();

At the end of this you'd have a list of all the genre objects in the database.

Wow. I think this is something I've been wanting to learn forever. Thanks. Now I just have to sort through it. (It's fun)

So each record a new 'myGenre' is loaded with data, and then added to the genrelist array collection...

In the meanwhile, I discovered how to iterate columns, so in theory I could use that to count them out. But I like your way.

It doesn't look reusable though. I would have to copy and adjust this code for each query set I wanted to play with though.

If that's fast and efficient, that's what I'll do
Frank Z
[COLOR="Gray"]
I used to ask 'why?' Now I just reinstall...
[SIZE="1"]______________________________________________
Author: ZTools: ZProcess, MVPServerChecker; UltraXMLTV Enhancer, Renamer, Manager; [/SIZE]
[/COLOR]
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,789
Threads: 769
Joined: Nov 2003
#13
2008-03-21, 10:56 PM
Quote:It doesn't look reusable though. I would have to copy and adjust this code for each query set I wanted to play with though.
You can create generic stuff if you want, but I prefer to deal with real types. For example, I have a channel manager object that has calls like ChannelManager.GetChannels(), which will return an ArrayList of channel objects. These Channels have attributes like Name, Number etc. This call and the channels are then used throughout the app. Thats pretty good reuse in my book, even though its not really what you mean.
zehd
Offline

Posting Freak

Posts: 5,119
Threads: 249
Joined: Feb 2006
#14
2008-03-21, 10:57 PM
sub Wrote:You can create generic stuff if you want, but I prefer to deal with real types. For example, I have a channel manager object that has calls like ChannelManager.GetChannels(), which will return an ArrayList of channel objects. These Channels have attributes like Name, Number etc.

THat sounds pretty organized. I like it.
Frank Z
[COLOR="Gray"]
I used to ask 'why?' Now I just reinstall...
[SIZE="1"]______________________________________________
Author: ZTools: ZProcess, MVPServerChecker; UltraXMLTV Enhancer, Renamer, Manager; [/SIZE]
[/COLOR]
zehd
Offline

Posting Freak

Posts: 5,119
Threads: 249
Joined: Feb 2006
#15
2008-03-21, 10:59 PM
I've got it mostly working, but I have an infinity error when it hist a record with argb not filled in, probably null. I guess I'll have to test for null, but I can't find the isnull function. Oh well. That's life with something new...
Frank Z
[COLOR="Gray"]
I used to ask 'why?' Now I just reinstall...
[SIZE="1"]______________________________________________
Author: ZTools: ZProcess, MVPServerChecker; UltraXMLTV Enhancer, Renamer, Manager; [/SIZE]
[/COLOR]
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,789
Threads: 769
Joined: Nov 2003
#16
2008-03-21, 11:08 PM
From memory its something like:

Object argb = dataReader.GetObject(dataReader.GetOrdinal("argb"));
if (Convert.IsDBNull(argb) == false)
{
argb = Convert.ToInt32(argb);
}
zehd
Offline

Posting Freak

Posts: 5,119
Threads: 249
Joined: Feb 2006
#17
2008-03-21, 11:09 PM
sub Wrote:From memory its something like:

Object argb = dataReader.GetObject(dataReader.GetOrdinal("argb"));
if (Convert.IsDBNull(argb) == false)
{
argb = Convert.ToInt32(argb);
}

Yuck
Frank Z
[COLOR="Gray"]
I used to ask 'why?' Now I just reinstall...
[SIZE="1"]______________________________________________
Author: ZTools: ZProcess, MVPServerChecker; UltraXMLTV Enhancer, Renamer, Manager; [/SIZE]
[/COLOR]
whurlston
Offline

Posting Freak

Posts: 7,885
Threads: 102
Joined: Nov 2006
#18
2008-03-21, 11:10 PM
in C#, you just do:

Code:
if (!object == null)
{
    // Process stuff here.
    // The exclamation point means "is not"
}
Not sure offhand the VB syntax.

Edit: I see sub's reply now.
zehd
Offline

Posting Freak

Posts: 5,119
Threads: 249
Joined: Feb 2006
#19
2008-03-21, 11:11 PM
zehd Wrote:Yuck

My SQL browser says that the argb_color column is actually a string field. Is that right?
Frank Z
[COLOR="Gray"]
I used to ask 'why?' Now I just reinstall...
[SIZE="1"]______________________________________________
Author: ZTools: ZProcess, MVPServerChecker; UltraXMLTV Enhancer, Renamer, Manager; [/SIZE]
[/COLOR]
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#20
2008-03-21, 11:15 PM
"Is nothing" in vb.net is equivalent to "== null"

And "if (not object is nothing) then" is the not clause.

But sometimes DB stuff doesn't recognise null, and needs the DBNull. Which is probably why sub has done it his way.
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (3): « Previous 1 2 3 Next »


Possibly Related Threads…
Thread Author Replies Views Last Post
  Starting the NPVR Built In Screensaver ACTCMS 2 1,714 2010-10-28, 05:55 PM
Last Post: ACTCMS
  .net / sqlite3 Date Types... zehd 4 4,715 2008-03-25, 01:36 AM
Last Post: zehd
  schedule a manual recording with sqlite3.exe jd142 4 2,333 2007-05-29, 09:13 PM
Last Post: sub
  Starting GBPVR with a different start page? gruskada 2 1,598 2006-02-01, 12:47 PM
Last Post: gruskada
  Starting a new skin chasef 16 5,071 2004-12-10, 07:57 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