473,379 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

problem creating a sql table

Hi,

I am getting a list text files and readig each of them and breaking down
each file string into a number of varibles. I want to create each table, if
it does not exist and add or update the data each time the program is ran in
an existing database.

The following code runs fine, except dsManager.Tables.a.Add( dt ) on the
second pass.

private void sql_update( string file_name, string var_type, int
core_items_count, string[] core_items )
{
// conn and reader declared outside try
// block for visibility in finally block
SqlConnection conn = null;
SqlDataReader reader = null;

try
{
// instantiate and open connection
conn = new
SqlConnection(
"Server=server;Database=testing;User=excalibur;Pwd =test" );
conn.Open();
}
finally
{
// close reader
if (reader != null)
{
reader.Close();
}

// close connection
if (conn != null)
{
conn.Close();
}
}
// check for table, create and build table if it does not exist -->
ex: passpc_form; name[ 1 ]_form

// catch error if database does not exist, create it!!!

DataTable dt = new DataTable( file_name );
DataColumn dc;

// add "var_type" Column
dc = dt.Columns.Add( "var_type", typeof( String ) );
dc.AllowDBNull = true;

// add "var_name" Column
dc = dt.Columns.Add( "var_name", typeof( String ) );
dc.AllowDBNull = true;

// Add "length" Column
dc = dt.Columns.Add( "length", typeof( int ) );
dc.AllowDBNull = true;

// Add "x" Column
dc = dt.Columns.Add( "x", typeof( int ) );
dc.AllowDBNull = true;

// Add "y" Column
dc = dt.Columns.Add( "y", typeof( int ) );
dc.AllowDBNull = true;

// if( dsManager.Tables.Count == 0 )
// why does "if( dsManager != null )" FAILS on the second pass?
if( dsManager != null )
{
dsManager.Tables.a.Add( dt );
}
// add data to table
switch( core_items_count )
{
case 1: dt.Rows.Add( new Object[] { core_items[ 0 ].Trim(), null,
null, null, null } );
break;
case 2: dt.Rows.Add( new Object[] { var_type, null, null,
core_items[ 0 ], core_items[ 1 ] } );
break;
case 3: dt.Rows.Add( new Object[] { var_type, null, core_items[ 0 ],
core_items[ 1 ], core_items[ 2 ] } );
break;
case 4: dt.Rows.Add( new Object[] { var_type, core_items[ 0 ],
core_items[ 1 ], core_items[ 2 ], core_items[ 3 ] } );
break;
}
}

What am i missing or doing wrong?

Thanks,

Jerry
Jan 30 '07 #1
0 1850

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

Similar topics

2
by: Keith | last post by:
I am having a problem creating a many-to-many-to-many type relationship. It works fine, but when I create a view to query it and test it, it does not generate the results I expected. Below...
15
by: Tamblyne | last post by:
This problem has got to have a simple solution and I can't be the first person who has ever handled it. Perhaps Google is no help because I'm not using the right terms? (I did find one post...
6
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone...
2
by: chettiar | last post by:
I am creating a procedure A which is creating a global temporary table DECLARE GLOBAL TEMPORARY TABLE session.temp (Service CHAR(2), CustomerServiceTypeId INTEGER) WITH REPLACE ON COMMIT PRESERVE...
3
by: erick-flores | last post by:
Hello all I am creating an Expense Report. There are to types of expenses: Company expenses and Reimb Expeneses. The company expenses is under "Expense Details Co" table and Reimb Expenses is...
4
by: Owen Jenkins | last post by:
Hi, No-one replied to this when I sent it last week. Any bites out there today?? ----- My application allows users to create a new back end for separate purposes. It does this by using Make...
17
by: radio1 | last post by:
Configuration: Access 2002 and SQL Server 2000 using a .ADP Project. I would VERY MUCH appreciate anyone's input into this problem I'm having. I have a form in Access that does not permit...
5
by: Will Honea | last post by:
I've hit an interesting trap trying to migrate data off an OS/2 server running version 7.2 (fp14) over to 8.2 on Linux. Seems that one table has a column defined in the DDL as "BIGINT NOT NULL...
0
by: vaskarbasak | last post by:
Hi All, we have a large table having 60 lakhs and more data.so we are facing a problem when we are executing insert or update query. as a result our DB is very slow and sometimes we are facing...
1
by: Ana RM | last post by:
Mark.Powell@eds.com (Mark D Powell) wrote in message news:<2687bb95.0308010642.1fc4ff1f@posting.google.com>... Hi Mark, Thanks por answer me. I do not think it is important thw warehouse...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.