Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Sqlite Data grid program Header Issue

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-15-2009, 07:30 PM
Junior Member
 
Join Date: Oct 2009
Location: India
Posts: 11
Default Sqlite Data grid program Header Issue

Dear Friend,

I have a customer table in SQLite DB. I need to show data from the table in my application.

Table definition is like

Table Name: Customer
Field Name1 : CustomerCode
Field Name2 : CustomerName

In my application the header of the data grid should be like

CUSTOMER CODE and CUSTOMER NAME instead of CustomerCode and CustomerName respectively.

that means I can define the header as I wish.

Here I used a form called CustView. and I used a controller Table called CustGrid

I used below code for this
CustGrid.AddCol(cString, "CUSTOMER CODE", 50)
CustGrid.AddCol(cString, "CUSTOMER NAME", 150)

But When I retrieve the data from the database table I got the header as in the table definition ie CustomerCode and CustomerName .

My Question is How I can define the header as I wish ?

My program is attached herewith as well as I am copying my code here.


Sub Globals
'Declare the global variables here.

End Sub

Sub App_Start

CreateConnection
CreateTableIfNotExists
Designer
CustView.Show

Connection.BeginTransaction
Command.CommandText = "SELECT * FROM customer"
Command.ExecuteTable("CustGrid", 1000)
Connection.EndTransaction

End Sub
Sub CreateConnection
Connection.New1
Command.New1("", Connection.Value)
Connection.Open("Data Source = " & AppPath & "\customer.sl3")

End Sub

Sub CreateTableIfNotExists
Command.CommandText = "SELECT name FROM sqlite_master WHERE type = 'table' AND name='customer'"
'instantiate reader
Reader.New1
'Fill reader
Reader.Value = Command.ExecuteReader
If Reader.ReadNextRow = False Then
' No table with this name in the database.
' Create one.
Reader.Close
Command.CommandText = "CREATE TABLE customer (CustomerCode TEXT PRIMARY KEY, CustomerName TEXT)"
Command.ExecuteNonQuery
Else
'Close reader anyhow
Reader.Close
End If
End Sub

Sub Designer

AddForm("CustView", "View Customer")
AddTable("CustView","CustGrid",30,50,200,150)
CustGrid.AddCol(cString, "CUSTOMER CODE", 50)
CustGrid.AddCol(cString, "CUSTOMER NAME", 150)
End Sub




Please see the attachment and run it


Expecting your help.

Thanking you

Jotis
Attached Files
File Type: zip dbtable.zip (6.1 KB, 14 views)

Last edited by jotis1 : 10-15-2009 at 07:33 PM.
Reply With Quote
  #2 (permalink)  
Old 10-16-2009, 07:44 AM
Junior Member
 
Join Date: Feb 2008
Location: Lubbock, TX
Posts: 36
Default Headers

Give this a try.
cmd.CommandText = "Select CustCode 'Customer Code',CustName 'Customer Name',Caddress 'Address',Ccity 'City',cphone 'Phone' from Customer Order by CustCode"

Using this method you can change your header to any thing want.

Hope this helps
Reply With Quote
  #3 (permalink)  
Old 10-16-2009, 09:19 AM
Basic4ppc Veteran
 
Join Date: Jul 2008
Location: Schwäbisch Gmünd
Posts: 353
Default

Hello jeterry,

I tried to find out a solution for jotis 1, but you are faster!
Your code works:
Quote:
Originally Posted by jeterry View Post
cmd.CommandText = "Select CustCode 'Customer Code',CustName 'Customer Name',Caddress 'Address',Ccity 'City',cphone 'Phone' from Customer Order by CustCode"
Another question:

Do you know how to show a table in another order of appearance? (not only the header)

Example: You have a table with 4 columns (Name, Date, Street, Item)

Now you want to show it in another appearance: (Item, Date, Street, Name)

Is there a easy way to do that?
__________________
JOTHA | Greetz from the Schwabenländle.
Pocket-PC: HTC HD2 (Dual-Boot WindowsMobile 6.51 + Android 2.2 Froyo)
Reply With Quote
  #4 (permalink)  
Old 10-16-2009, 10:30 AM
Junior Member
 
Join Date: Feb 2008
Location: Lubbock, TX
Posts: 36
Default Header

How you make your select statement, I believe is how the data will appear in the data grid. As per your example, select item,date,street,name from table. The data should be displayed as follows: col0=item,col1=date,col2=street,col3=name

Correct me if I am wrong, the selection statement is how the grid will display the data.

Hope that helps
Reply With Quote
  #5 (permalink)  
Old 10-16-2009, 12:19 PM
Basic4ppc Veteran
 
Join Date: Jul 2008
Location: Schwäbisch Gmünd
Posts: 353
Thumbs up

Hello jeterry,

thank you for your fast answer.
Quote:
Originally Posted by jeterry View Post
... Correct me if I am wrong ...
YOU ARE RIGHT!

__________________
JOTHA | Greetz from the Schwabenländle.
Pocket-PC: HTC HD2 (Dual-Boot WindowsMobile 6.51 + Android 2.2 Froyo)
Reply With Quote
  #6 (permalink)  
Old 10-16-2009, 12:26 PM
Junior Member
 
Join Date: Oct 2009
Location: India
Posts: 11
Default

Dear Jeterry/Jotha/Friends

Thanks for your support.
I forg0t to say one thing. My program support Multiple Language.
I keep a text_translation table where I can select languages for correspnding variable.

For eg: I keep two variable, 1. Customer 2. CustomerName

In Text Translation table, there will be corresponding text for each variable.

I need to bring the header in multilanguage support.

I don't think I can mix with a variable in SQL Query. If possible just help me.
Or do you know another way ?

Anyway with Table.AddCol() function ?
I used it but didn't get the value if I run an sql query. May be my coding mistake.


For eg: Just see the code

Sub App_Start

CreateConnection
CreateTableIfNotExists
Designer
CustView.Show

CustCodeText= "CUSTOMER CODE"
CustNameText= "CUSTOMER NAME"
CustGrid.AddCol(cString, CustCodeText, 50)
CustGrid.AddCol(cString, CustNameText, 150)

Connection.BeginTransaction
Command.CommandText = "SELECT * FROM customer"
Command.ExecuteTable("CustGrid", 1000)
Connection.EndTransaction



End Sub
Sub Designer

AddForm("CustView", "View Customer")
AddTable("CustView","CustGrid",30,50,200,150)
End Sub

HERE IF I comment the SQL Fetching Program, I get the header as per my requirement or as I defnined.
But If I call the SQL program I didnt get the header as per my requirement and instead I got the coloumn name of table definition.

I don't need the coloumn name, I need to define as I wish and it should be change along with How I select a language.
If I select Spanish as my default language It should be spanish text.
If I select English it will be in English

Please help

Last edited by jotis1 : 10-16-2009 at 01:44 PM.
Reply With Quote
  #7 (permalink)  
Old 10-16-2009, 02:22 PM
Junior Member
 
Join Date: Oct 2009
Location: India
Posts: 11
Default

Dear Friends,

Thank you for support.

I findout another way. I think its ok now.
If you know another way just inform me

Please see my solution

Sub App_Start

CreateConnection
CreateTableIfNotExists
Designer
CustView.Show
CustCodeText= "CUSTOMER CODE"
CustNameText= "CUSTOMER NAME"
CustGrid.AddCol(cString, CustCodeText, 50)
CustGrid.AddCol(cString, CustNameText, 150)
Connection.BeginTransaction
Command.CommandText = "SELECT * FROM customer"
'Command.ExecuteTable("CustGrid", 1000)
Reader.Value = Command.ExecuteReader
Do While Reader.ReadNextRow = True
CustGrid.AddRow (Reader.GetValue(0), Reader.GetValue(1))

Loop


Connection.EndTransaction



End Sub

Thanks
Jotis
Reply With Quote
  #8 (permalink)  
Old 10-16-2009, 04:03 PM
Ariel_Z's Avatar
Basic4ppc Veteran
 
Join Date: May 2009
Posts: 246
Default

As Jeterry said, you can use this syntax to create the SELECT statement:
Code:
cmd.CommandText = "Select CustCode 'Customer Code',CustName 'Customer Name',Caddress 'Address',Ccity 'City',cphone 'Phone' from Customer Order by CustCode"
But if you wish, you can use variables in the statement. Suppose strCusNameCol is a variable holding the name of your column:
Code:
cmd.CommandText = "Select CustName '" & strCusNameCol  & "'"
(note the last ' between the two "...)

Now put the column name in strCusNameCol and executeTable... Should be faster, I believe, than populating the table manually.
Reply With Quote
  #9 (permalink)  
Old 10-18-2009, 08:25 AM
Junior Member
 
Join Date: Oct 2009
Location: India
Posts: 11
Default

Thank you Ariel

rgds
Jotis
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert data csv to sl3(SQLite) JJM Questions (Windows Mobile) 9 03-22-2010 03:07 PM
Fastest way to display SQLite data? RB Smissaert Questions (Windows Mobile) 11 12-06-2008 03:29 PM
SQLite example program Lightyear Questions (Windows Mobile) 3 09-14-2008 02:21 PM
Sqlite Data Sequence ceaser Questions (Windows Mobile) 2 07-29-2008 11:03 AM
Data collection from devices to Desktop using SQLite mozaharul Questions (Windows Mobile) 3 04-03-2008 10:00 AM


All times are GMT. The time now is 10:30 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0