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...
zehd
Offline

Posting Freak

Posts: 5,119
Threads: 249
Joined: Feb 2006
#21
2008-03-21, 11:23 PM
psycik Wrote:"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.

Can't get the affirmative or negative going. Searching everywhere for inline check. Might have to build a errhandler...
Code:
If dataReader.GetString(dataReader.GetOrdinal("argb_color")) Is Nothing Then
                myGenre.argb = ""
            Else
                myGenre.argb = dataReader.GetString(dataReader.GetOrdinal("argb_color"))
            End If
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
#22
2008-03-21, 11:25 PM
sub Wrote:From memory its something like:

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

So I guess I could set the

Code:
Public Class Genre
        Public oid As Integer
        Public genreName As String
        Public argb As [B]Object[/B]
End Class

And then test with isdbnull
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
#23
2008-03-21, 11:36 PM
How's this? No errors. But then is the argb_color suppsoed to be string type?

Code:
Public Class Genre
        Public oid As Integer
        Public genreName As String
        Public argb As String
    End Class


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        SQL_connection.ConnectionString = "Data Source=" & GBPVRdb3 & ";Version=3;New=True;"
        SQL_connection.Open()

        Dim command As DbCommand = DbProviderFactory.CreateCommand()
        command.Connection = SQL_connection
        command.CommandText = "SELECT * from GENRE"
        Dim dataReader As DbDataReader = command.ExecuteReader()


        While dataReader.Read() 'iterates all fileds
            Dim myGenre = New Genre()
            myGenre.oid = dataReader.GetInt32(dataReader.GetOrdinal("oid"))
            myGenre.genreName = dataReader.GetString(dataReader.GetOrdinal("genre_name"))
            If (Not Convert.IsDBNull(dataReader.GetValue(dataReader.GetOrdinal("argb_color")))) Then
                myGenre.argb = CStr(dataReader.GetString(dataReader.GetOrdinal("argb_color")))
            End If
            genreList.Add(myGenre)
        End While
        dataReader.Close()

    End Sub
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
#24
2008-03-22, 12:00 AM
Totally got it. Thanks guys..
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]
HtV
Offline

Posting Freak

Posts: 3,470
Threads: 46
Joined: Dec 2005
#25
2008-03-22, 12:01 AM
Well if you go on like this you'll have 10.000 posts in 2 weeks.Big Grin
Good luck with it.

Hans
AMD Athlon 64 3000, HDD: 80, 120, 200 GB, Hauppauge 350 + 150, MVP, Asus 6000L Laptop client, Asus X50sl client,
Fritz!box 7140 modem/router, GBPVR 1.3.7.
zehd
Offline

Posting Freak

Posts: 5,119
Threads: 249
Joined: Feb 2006
#26
2008-03-22, 12:09 AM
HtV Wrote:Well if you go on like this you'll have 10.000 posts in 2 weeks.Big Grin
Good luck with it.

Hans

Now we know how sub has so many posts. He was just winging 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]
Fatman_do
Offline

Posting Freak

Posts: 3,482
Threads: 95
Joined: Nov 2005
#27
2008-03-22, 12:43 AM
zehd Wrote:Now we know how sub has so many posts. He was just winging it...

Just think if he threw in a poll about chicken !!!eleven!!!!!!1111!!??teen!!


And NO!.. this isn't a useless post on my part in a thread I have nothing to do with just to get my post count up.
Fatman_do
[SIZE="1"]
HTPC: AMD XP+2500, 512MB DDR (400) ~ Capture Device: Hauppage PVR-150
Storage: 30GB OS & Recording, 160GB Post Processing & Archive
Video Output: HD 32" TV via eVGA Geforce 6200le 256MB AGP DVI-HDMI cable out
Audio Output: Turtle Beach Riviera S/PDIF Optic Output (Digital pass thru only) to Home Theater Receiver[/SIZE]

[SIZE="2"]
Moderator | Tutorials | Community Skin | CommunitySkin-SVN[/SIZE]
zehd
Offline

Posting Freak

Posts: 5,119
Threads: 249
Joined: Feb 2006
#28
2008-03-22, 05:31 AM
Rtflmol
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
#29
2009-02-26, 08:54 PM (This post was last modified: 2009-02-26, 09:01 PM by zehd.)
Thought I'd resurrect this thread... What the heck

I've been searching for ways to reduce some code clutter and I wanted to see if I could concatenate a variable. I have serached on the net quite a bit, so maybe I don't know what I'm asking... here's the scopp

This is for getting and setting info into an SQLITE3 Table...

Code:
Public Class Programme
    Public oid As Integer
    Public name As String
    Public sub_title As String
    Public description As String
    Public start_time As DateTime
    Public end_time As DateTime
    Public channel_oid As Integer
    Public unique_identifier As String
    Public rating As String
End Class

I create an instance and populate the variables.

Code:
(some snipped)

        While dataReader.Read()

            myDB_Programme = New Programme

            myDB_Programme.oid = dataReader.GetInt32(dataReader.GetOrdinal("oid"))
            myDB_Programme.name = dataReader.GetString(dataReader.GetOrdinal("name"))
            myDB_Programme.sub_title = dataReader.GetString(dataReader.GetOrdinal("sub_title"))
            myDB_Programme.description = dataReader.GetString(dataReader.GetOrdinal("description"))
            myDB_Programme.start_time = dataReader.GetString(dataReader.GetOrdinal("start_time"))
            myDB_Programme.end_time = dataReader.GetString(dataReader.GetOrdinal("end_time"))
            myDB_Programme.channel_oid = dataReader.GetInt32(dataReader.GetOrdinal("channel_oid"))
            myDB_Programme.unique_identifier = dataReader.GetString(dataReader.GetOrdinal("unique_identifier"))
            If (Not Convert.IsDBNull(dataReader.GetValue(dataReader.GetOrdinal("rating")))) Then myDB_Programme.rating = dataReader.GetString(dataReader.GetOrdinal("rating"))

            ProgrammeList.Add(myDB_Programme)

        End While

Due to my query, I actually only have one record filled with values. myDB_Programme is public, so I can get and set the value outside. I change one property

Code:
myDB_Programme.description = "Test2"

So far so good.

Now I want to update the table with the new data. I Know how to do it, if I select the properties...

Here's the section where I build the SQL statement to update the fileds. I have it set to update the whole record, (though in this section, only one field has been changed.

Code:
With myDB_Programme
            'theis record is indexed on oid, so there's no changing it...
            command.CommandText = "UPDATE OR REPLACE PROGRAMME SET " & _
                    "name = '" & .name & "', " & _
                    "sub_title = '" & .sub_title & "', " & _
                    "description = '" & .description & "', " & _
                    "start_time = '" & .start_time & "', " & _
                    "end_time = '" & .end_time & "', " & _
                    "channel_oid = '" & .channel_oid & "', " & _
                    "unique_identifier = '" & .unique_identifier & "', " & _
                    "rating = '" & .rating & "' " & _
                    "WHERE oid =" & param_oid
        End With
        MsgBox(command.CommandText)

Sure I could shorten up the SQL if I only set the 'description' but this is supposed to be more versatile.

I call the set procedure, by passing the oid I want to single out, and the property that I want to update

Code:
Set1_Programme_by_oid("2975", "description", "Test2")


Code:
Sub Set1_Programme_by_oid(ByVal param_oid As Integer, ByVal paramTag As String, ByVal SetValue As Object)


        'first query and fill the mydb_programme object
        Get1_Programme_by_oid(param_oid)

        With myDB_Programme
            Select Case paramTag
                Case "name"
                    .name = SetValue
                Case "sub_title"
                    .sub_title = SetValue
                Case "description"
                    .description = SetValue
                Case "start_time"
                    .start_time = SetValue
                Case "end_time"
                    .end_time = SetValue
                Case "channel_oid"
                    .channel_oid = SetValue
                Case "unique_identifier"
                    .unique_identifier = SetValue
                Case "rating"
                    .rating = SetValue
            End Select
        End With

What I want to do is THIS:

Code:
With myDB_Programme
         "." & paramTag = SetValue
End with

Of course I know that this won't work. I just create a string ("." & paramTag) but I want to turn that string into a class property
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
#30
2009-02-26, 09:32 PM
Hmm, I think you do what you want, but it's not in one line....

This takes the object, and figures out the public (browsable) properties of that class/object. From there it does stuff with them. Sorry that it's C#

Code:
private static System.Collections.Hashtable EnumerateProperties(object objectToEnumerate)
        {

            PropertyInfo[] properties = (objectToEnumerate.GetType()).GetProperties(BindingFlags.Public | BindingFlags.Instance);
            System.Collections.Hashtable newProperties = new System.Collections.Hashtable();
            for (int i = 0; i < properties.Length; i++)
            {
                //check if there is set accessor
                if (null != properties[i].GetSetMethod())
                {
                    object name = properties[i].Name;
                    object value = "";
                    if (properties[i] != null && properties[i].GetValue(objectToEnumerate, null) != null)
                        value = properties[i].GetValue(objectToEnumerate, null);
                    
                    AttributeCollection attributes = TypeDescriptor.GetProperties(objectToEnumerate)[name.ToString()].Attributes;
                    if (attributes[typeof(BrowsableAttribute)].Equals(BrowsableAttribute.Yes))
                    {
                        //Added so you can now put in nested properties by using the [XmlElement("level1/elemeet")] option on properties.
                        //See UpdateURL for example
                        if (attributes[typeof(XmlElementAttribute)] != null)
                        {
                            XmlElementAttribute tempAttr = (XmlElementAttribute)attributes[typeof(XmlElementAttribute)];
                            if (tempAttr.ElementName.Length > 0)
                                name = tempAttr.ElementName;

                        }
                        newProperties.Add(name, value);
                    }



                }
            }
            return newProperties;
        }


So not sure if you'd be able to use it. I wrote this as a settings class where I gave it an object but wanted more control over its serialisation. So you may be able to adapt it to using a DB....
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (3): « Previous 1 2 3


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