I need this code converted to visual studio 2005.... I am parsing some data in a database... All help will be appreciated and awarded to the one who can complete this task....
-JEB
using System;
using System.Collections.Generic
;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace qatdata
{
public partial class frmConvert : Form
{
public frmConvert()
{
InitializeComponent();
// GetData();
}
private void GetData() {
DataTable dt = new DataTable();
OleDbConnection con = new OleDbConnection(@"Provider
=Microsoft
.Jet.OLEDB
.4.0;Data Source=d:\csharpprojects\q
at\QAT_Pro
ducts.mdb;
User Id=admin;Password=;");
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText = "Select * From ProductUpdate where title > '' Order by Category";
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(dt);
dt.Columns.Add("Cat",typeo
f(string))
;
dt.Columns.Add("Cat2",type
of(string)
);
dt.Columns.Add("Cat3", typeof(string));
dt.Columns.Add("SubCatID",
typeof(int));
String[] aHolder;
foreach (DataRow dr in dt.Rows)
{
aHolder = dr["Category"].ToString().
Split(new string[] { @"///" },System.StringSplitOption
s.None);
if (aHolder.Length > 0)
dr["Cat"] = aHolder[0];
if( aHolder.Length >1)
dr["Cat2"] = aHolder[1];
if (aHolder.Length > 2)
dr["Cat3"] = aHolder[2];
}
string InsertString,LastCat="x", LastSub="x";
int Cat=0,SubCat=0;
foreach (DataRow dr in dt.Rows) ///this routine could be added to the above loop.. but speed is not an issue here
{
if(LastCat!=dr["Cat"].ToSt
ring())//c
hanging insert new id
{ Cat++;//increment id
LastCat=dr["Cat"].ToString
();
InsertString = string.Format("insert into Categories(CategoryID,Pare
ntID,Categ
oryName)Va
lues({0},{
1},{2})",C
at,0,LastC
at);
InsertID(InsertString);
}
if(LastSub!=dr["Cat2"].ToS
tring())//
changing insert new subid
{ SubCat++;//increment id
LastSub=dr["Cat2"].ToStrin
g();
InsertString = string.Format("insert into Categories(CategoryID,Pare
ntID,Categ
oryName)Va
lues({0},{
1},{2})",S
ubCat,Cat,
LastSub);
InsertID(InsertString);
}
dr["SubCatID"] = SubCat;//< this is just for show inserting should be done on different table
//add other columns as needed...
InsertString = string.Format("insert into Products(CategoryIDs,Produ
ctName)Val
ues({0},{1
})", SubCat,dr["Title"]);
InsertProduct(InsertString
);
}
this.dataGridView1.DataSou
rce = dt;
}
private void InsertID(string p_InsertString)
{
//do insert here
//example:
OleDbConnection con = new OleDbConnection(@"Provider
=Microsoft
.Jet.OLEDB
.4.0;Data Source=d:\csharpprojects\q
at\Categor
ies.mdb;Us
er Id=admin;Password=;");
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText = p_InsertString;
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message
);
}
finally { con.Close(); }
return;
}
private void InsertProduct(string p_InsertString)
{
//do insert here
return;
}
private void button1_Click(object sender, EventArgs e)
{
GetData();
}
private void frmConvert_Load(object sender, EventArgs e)
{
}
private void dataGridView1_CellContentC
lick(objec
t sender, DataGridViewCellEventArgs e)
{
}
}
}
Start Free Trial