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.

Updating multiple columns in SQLite

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-07-2008, 03:19 AM
Senior Member
 
Join Date: Mar 2008
Location: Dhaka, Bangladesh
Posts: 164
Default Updating multiple columns in SQLite

I’m using a table control to make change in multiple columns and want to update those changes in the database by the click event of a button. The numbers of columns to be changed are arbitrary (some time 2 columns, some time 4 columns are to be changed). The statement to update a single column :

cmd.CommandText = "update table-name set column1 = '"&txtbox1.Text&"' where column2= '"& txtbox2.Text& "';"

Then do I have to use as many textboxes as the numbers of columns I want to update? Or there is a way to update the whole table at once without using textboxes?

Please give some guideline.

Thanks and regards
Reply With Quote
  #2 (permalink)  
Old 04-07-2008, 07:19 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,733
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Where is the new data stored (textbox, variable...)?
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 02:53 AM
Senior Member
 
Join Date: Mar 2008
Location: Dhaka, Bangladesh
Posts: 164
Default

I changed the table's column value directly through a textbox like:

Sub Btnchange_Click
If txtfilter.Text="" Then
Msgbox("No column to change")
Else If Table2.SelectedRow < Table2.RowCount Then
Table2.Cell(Table2.SelectedCol,Table2.SelectedRow) = txtfilter.Text
End If
btnupload.Enabled=true
End Sub

In this way I can change as many columns as it is required.
... ...
... ...

Then can update a single column like:

Sub Btnupload_Click
cmd.CommandText = "update geo set ed = '"&txtfilter.Text&"'where hpid = '"& txtsearch.Text& "';"
cmd.ExecuteNonQuery
End Sub


But the changes made to other columns are not updated.

Thanks for your valuable time.
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 07:27 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,733
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

You can update multiple columns by using:
"UPDATE geo SET col1 = 'value1', col2 = 'value2', col3 = 'value3' WHERE ..."
Use Table.Cell to read the values from the table.
Reply With Quote
  #5 (permalink)  
Old 02-21-2010, 01:46 PM
Junior Member
 
Join Date: Jul 2009
Location: Derbyshire, UK
Posts: 36
Default

It's a good idea to add Parameters for each value; then you don't need to worry about delimiting strings, and escaping "'" characters. Also, if you're using values the user has typed in, it avoids "SQL insertion" (adding ";" and extra SQL commands).

Sub AddCmdParams
' Parish,Street,Position,BarCode,Support,CType,Mater ial,Protection,..
Cmd.AddParameter("Parish")
Cmd.AddParameter("Street")
...
then:
sSQL = "Update tblColumns Set "
Conn.BeginTransaction
sTmp = txtParish.Text ' get value from form textbox (or combo)
tblData.Cell("Parish",Row) = sTmp ' update table from form
sSQL = sSQL & "Parish=@Parish, "
Cmd.SetParameter("Parish",sTmp)

(repeat for additional fields; omit final comma!)
now add condition (primary key):
sTmp = " WHERE (UN_Unit='" & Unit_ID & "')"
sSQL = sSQL & sTmp
cmd.CommandText = sSQL
iTmp = Cmd.ExecuteNonQuery
If iTmp <> 1 Then Msgbox(iTmp & " records updated") ' should be only 1 record!
Conn.EndTransaction

I used panels to display and update groups of fields; the table control was in the background, and could be saved to a CSV file, as well as the database.
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
Deleting multiple files at ones sonavep Questions (Windows Mobile) 2 04-21-2008 03:00 PM
Multiple Listviews tsteward Questions (Windows Mobile) 2 04-20-2008 10:16 AM
Multiple Instances of an application Louis Questions (Windows Mobile) 1 12-23-2007 05:20 AM
How to play multiple sounds at once? justdo Questions (Windows Mobile) 2 09-24-2007 03:59 AM
multiple connections to a sqlite database Peter Questions (Windows Mobile) 5 05-13-2007 07:49 AM


All times are GMT. The time now is 09:11 AM.


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