473,785 Members | 2,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding data columns to a disconnected database

I am having trouble adding data columns to a disconnected database. I
first load a datatable using:
private DataTable dtMacros = new DataTable();
private ArrayList macro = new ArrayList();
private SQLiteConnectio n cn;
private SQLiteDataAdapt er adapterMacros;
cn = new SQLiteConnectio n("Data Source = irDatabase.db3" );
SQLiteCommand commandMacros = new SQLiteCommand() ;
commandMacros.C ommandText = "SELECT * FROM irMacros";
adapterMacros = new SQLiteDataAdapt er(commandMacro s.CommandText,
cn);
SQLiteCommandBu ilder builderMacros = new
SQLiteCommandBu ilder(adapterMa cros);
adapterMacros.F ill(dtMacros);
dtMacros.Primar yKey = new DataColumn[]
{ dtMacros.Column s["MacroName"] };

I am using an arraylist (macro) to store values for a new row - all
values are strings.

Later I update the data with the following code:
private void UpdateMacroData base(ArrayList macro, string macroName)
{
//Add datatable columns if needed for the datatable in
memory
if (dtMacros.Colum ns.Count <= macro.Count)
{
int i = dtMacros.Column s.Count;
while (i <= macro.Count)
{
dtMacros.Column s.Add("Command" + (i-1).ToString(),
typeof(String)) ;
i++;
}
}
//update the datatable in memory
DataRow row = dtMacros.Rows.F ind(macroName);
if (row == null)
{
row = dtMacros.NewRow ();
row[0] = macroName;
for (int i = 0; i < macro.Count; i++)
{
row[i+1] = macro[i];
}
dtMacros.Rows.A dd(row);
}
else
{
row["MacroName"] = macroName;
for (int i = 1; i <= macro.Count; i++)
{
row[i] = macro[i - 1];
}
}
adapterMacros.U pdate(dtMacros) ;
dtMacros.Accept Changes();
macro.Clear();
}

The datatable in memory adds the new columns and rows as it should.
The database on disk will add the new rows and will update the
columns, but will not add the new columns.

Thanks for any help.

Regards,
Gary B
Jan 2 '08 #1
2 3372
Hi,
You need to add the columns in the "real" DB, which makes me wonder, why
they are not there in the first place?

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"canoewhite h2o" <ca***********@ yahoo.comwrote in message
news:4e******** *************** ***********@z11 g2000hsf.google groups.com...
>I am having trouble adding data columns to a disconnected database. I
first load a datatable using:
private DataTable dtMacros = new DataTable();
private ArrayList macro = new ArrayList();
private SQLiteConnectio n cn;
private SQLiteDataAdapt er adapterMacros;
cn = new SQLiteConnectio n("Data Source = irDatabase.db3" );
SQLiteCommand commandMacros = new SQLiteCommand() ;
commandMacros.C ommandText = "SELECT * FROM irMacros";
adapterMacros = new SQLiteDataAdapt er(commandMacro s.CommandText,
cn);
SQLiteCommandBu ilder builderMacros = new
SQLiteCommandBu ilder(adapterMa cros);
adapterMacros.F ill(dtMacros);
dtMacros.Primar yKey = new DataColumn[]
{ dtMacros.Column s["MacroName"] };

I am using an arraylist (macro) to store values for a new row - all
values are strings.

Later I update the data with the following code:
private void UpdateMacroData base(ArrayList macro, string macroName)
{
//Add datatable columns if needed for the datatable in
memory
if (dtMacros.Colum ns.Count <= macro.Count)
{
int i = dtMacros.Column s.Count;
while (i <= macro.Count)
{
dtMacros.Column s.Add("Command" + (i-1).ToString(),
typeof(String)) ;
i++;
}
}
//update the datatable in memory
DataRow row = dtMacros.Rows.F ind(macroName);
if (row == null)
{
row = dtMacros.NewRow ();
row[0] = macroName;
for (int i = 0; i < macro.Count; i++)
{
row[i+1] = macro[i];
}
dtMacros.Rows.A dd(row);
}
else
{
row["MacroName"] = macroName;
for (int i = 1; i <= macro.Count; i++)
{
row[i] = macro[i - 1];
}
}
adapterMacros.U pdate(dtMacros) ;
dtMacros.Accept Changes();
macro.Clear();
}

The datatable in memory adds the new columns and rows as it should.
The database on disk will add the new rows and will update the
columns, but will not add the new columns.

Thanks for any help.

Regards,
Gary B


Jan 2 '08 #2
Well they are not there in the first place because I am allowing the
user to increase the number of columns based on user need. I am using
the db to store mouse clicks within a macro.

Anyway, I did figured it out. I threw away the CommandBuilder and
constructed my on sql strings. Probably should have taken that
approach in the first place.
Jan 6 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2880
by: elcc1958 | last post by:
I need to support a VB6 application that will be receiving disconnected ADODB.Recordset from out DotNet solution. Our dotnet solution deals with System.Data.DataTable. I need to populate a disconnected ADODB.Recordset from System.Data.DataTable data. Below is the source code I am implementing to test the process. I do not get any error, that I can see. The problem I have is that at the end, the recordset seems to be empty. Any...
2
1430
by: Phil | last post by:
I have the following code but do not know the best way to return the updated DataTable back to the database. I believe I can use the Update method of the Data Adapter, BUT if true, I also believe I have to 'long-hand' write code for each individual column data that's being added......this seems a bit daft considering that the data is already in the disconnected data table. Have I lost the plot?? Based on the code below, what is the correct...
5
1369
by: Nick Stansbury | last post by:
Hi, Sorry for the obscure title but I'm afraid I can't think of a better way to describe what happened to one of my clerks last night. The guy was working late, made a series of changes (accross a number of tables with a dependant relationship structure - i.e. a customer linked to an order linked to an invoice linked to a payments etc.) Now when he came back this morning none of the work he did last night was still there. I'm by no means...
3
4885
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
3
1955
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple example would be: Let's say Column1=StartDate and Column2=EndDate. In addition to displaying Column1 and Column2, I need to do some calculations and display in as Column3. The calculations are easy and can be done in the code-behind. How to display...
1
3297
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple days of struggling, I figure asking you all (the experts) will keep me from going down some dark and dangerous road. The project I have is a fairly simple one, in theory anyway. The gist is to create a page where the user enters an IDNumber,...
2
1411
by: naija naija | last post by:
Hello guys i made a Datagrid with Editing,Update and Cancel using VS.NET. to my surprise nothing is on the screen after compilation .. By code below:- Imports System.Data Imports System.Data.SqlClient Imports System.Web.UI.WebControls Imports System.Web.UI.HtmlControls Public Class datagrid_edit Inherits System.Web.UI.Page
7
1788
by: Miro | last post by:
Im a VB Newbie so I hope I'm going about this in the right direction. I have a simple DB that has 1 Table called DBVersion and in that table the column is CurVersion ( String ) Im trying to connect to the db, and then add a record to the DBVersion table. Except I cant. I have 1 line that crashes and if i rem it out it works but nothing gets added.
12
6223
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the datagrid. Once I can get to that point I need some way to be able to add new data only to the new columns that were added. Here is some of my code: //Function For Importing Data From CSV File public DataSet ConnectCSV(string filetable)
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10329
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.