473,614 Members | 2,089 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Help... Convert VB.NET to C#

Hello All,
I am stuck on a conversion problem. I am trying to convert my
application which is written in VB.NET to C# because the project I am
working on currently is being written in C#.
I tried my best to convert it, but somehow the app does not work. I am
also not getting any errors when I complie thus, letting me know I am
on the write track. Basically what I want to do is edit,add,delete , and
update an XML file in a DataGrid. Below is my Code in

sub LoadXML
Dim objdata as New DataSet
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer
Try

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"))
datagrid1.Datas ource=objdata
datagrid1.Datab ind()

Catch

CreateXML

End Try
End sub
Sub CreateXML
Dim objdata as New DataSet("Indian Master")
Dim dt as New DataTable("Prod uct")
Dim dr as DataRow
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer

dt.Columns.Add( New DataColumn("NAM E"))
dt.Columns.Add( New DataColumn("SKU "))
dt.Columns.Add( New DataColumn("PRI CE"))
dt.Columns.Add( New DataColumn("TYP E"))

dr=dt.NewRow()
dr(0)="No Data"
dr(1)="No Data"
dr(2)="No Data"
dr(3)="No Data"

dt.Rows.Add(dr)

objdata.Tables. Add(dt)

datagrid1.datas ource=objdata
datagrid1.datab ind()
objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"))

LoadXML()
End Sub
Sub setEditMode(Sen der as Object, E as DataGridCommand EventArgs)

Dim objdata as New DataSet
Dim x1 as string
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"))

x1=datagrid1.Da taKeys.Item(e.I tem.ItemIndex)

objdata.Tables( "Product").Defa ultView.RowFilt er="NAME='" & x1 &
"'"

If objdata.Tables( "Product").Defa ultView.Count>0 Then
error4.visible= "False"
datagrid1.EditI temIndex=E.Item .ItemIndex
datagrid1.showf ooter="false"
LoadXML
Else
error4.visible= "True"
End If
End sub
Sub cancelEdit(send er as Object, E as DataGridCommand EventArgs)
datagrid1.EditI temIndex=-1
datagrid1.showf ooter="true"
error1.visible= "False"
error2.visible= "False"
error3.visible= "False"
error4.visible= "False"
error5.visible= "False"

LoadXML

End sub
Sub DelXML(S as Object, E as DataGridCommand EventArgs)
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer
If e.CommandName=" Delete" Then
If datagrid1.EditI temIndex=-1 Then
error5.visible= "False"
Dim x1 as string

x1=datagrid1.Da taKeys.Item(e.I tem.ItemIndex)

Dim objdata as New DataSet

Try

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"))
objdata.Tables( "Product").Defa ultView.RowFilt er="NAME='" &
x1 & "'"
If objdata.Tables( "Product").Defa ultView.Count>0 Then
objdata.Tables( "Product").Defa ultView.Delete( 0)
End If

objdata.Tables( "Product").Defa ultView.RowFilt er=""
objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"))
Catch
CreateXML
End Try

LoadXML
Else
error5.visible= "True"
End If
End if
End Sub
Sub UpdateXML(s as Object, e as DataGridCommand EventArgs)
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer
If e.CommandName=" Update" Then
Dim str1, str2, str3,v1 as string
Dim txt1,txt2,txt3, txt4 as Textbox
Dim objdata as New DataSet
Dim x1 as string

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"))

v1=e.Item.ItemI ndex

x1=datagrid1.Da taKeys.Item(e.I tem.ItemIndex)

objdata.Tables( "Product").Defa ultView.RowFilt er="NAME='" & x1 &
"'"

If objdata.Tables( "Product").Defa ultView.Count>0 Then
error3.visible= "False"

txt1=e.Item.Fin dControl("name_ edit")
txt2=e.Item.Fin dControl("sku_e dit")
txt3=e.Item.Fin dControl("price _edit")
txt4=e.Item.Fin dControl("type_ edit")
objdata.Tables( "Product").Rows (v1).Item("NAME ")=txt1.Tex t
objdata.Tables( "Product").Rows (v1).Item("SKU" )=txt2.Text
objdata.Tables( "Product").Rows (v1).Item("PRIC E")=txt3.Tex t
objdata.Tables( "Product").Rows (v1).Item("TYPE ")=txt4.Tex t
datagrid1.datas ource=objdata
datagrid1.datab ind()
objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"))

datagrid1.EditI temIndex=-1
LoadXML
datagrid1.showf ooter="true"
Else
error3.visible= "True"
End If
End If
End sub
Sub doInsert(s as Object, E as DataGridCommand EventArgs)
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer

if e.CommandName=" doAdd" Then
Dim v1 as string
Dim tadd1,tadd2,tad d3,tadd4 as Textbox
Dim objdata as New DataSet
Dim dr as DataRow

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"))

tadd1=e.Item.Fi ndControl("name _add")
tadd2=e.Item.Fi ndControl("sku_ add")
tadd3=e.Item.Fi ndControl("pric e_add")
tadd4=e.Item.Fi ndControl("type _add")

Try
'tadd1.text=int 32.parse(tadd1. text)
error2.visible= "false"

If tadd1.text="" Then
' tadd1.Text=""
error2.visible= "true"
End If
Catch
tadd1.text=""
error2.visible= "true"
End Try

If tadd1.Text<>"" and tadd2.Text<>"" and tadd3.Text<>"" Then
objdata.Tables( "Product").Defa ultView.RowFilt er="NAME='" &
tadd1.Text & "'"
If objdata.Tables( "Product").Defa ultView.Count<= 0 Then
error1.visible= "False"
objdata.Tables( "Product").Defa ultView.RowFilt er=""
dr=objdata.Tabl es("Product").N ewRow()

dr(0)=tadd1.Tex t
dr(1)=tadd2.Tex t
dr(2)=tadd3.Tex t
dr(3)=tadd4.Tex t
objdata.Tables( "Product").Rows .Add(dr)
objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"))
LoadXML
Else
error1.visible= "True"
error1.Text="Pr oduct must be unique"
End If
End If
End If
End Sub

Here is my C# Code:

void LoadXML()
{
DataSet objdata = new DataSet();
orderc = user.SelectedIt em.Value.ToStri ng();
objdata.ReadXml (Server.MapPath ("OrderGuide s/" + orderc + ".xml"));
datagrid1.DataS ource = objdata;
datagrid1.DataB ind();

}

private DataSet CreateDataSourc e()
{
XmlDataDocument mydata = new XmlDataDocument ();
orderc = user.SelectedIt em.Value.ToStri ng();
mydata.DataSet. ReadXml(Server. MapPath("OrderG uides/" + orderc +
".xml"));
return mydata.DataSet;
}
void CreateXML()
{
DataSet objdata = new DataSet("Indian Master");
DataTable dt = new DataTable("Prod uct");
DataRow dr;
orderc = user.SelectedIt em.Value.ToStri ng();
dt.Columns.Add( "NAME");
dt.Columns.Add( "SKU");
dt.Columns.Add( "PRICE");
dt.Columns.Add( "TYPE");
dr = dt.NewRow();
dr[0] = "No Data";
dr[1] = "No Data";
dr[2] = "No Data";
dr[3] = "No Data";
dt.Rows.Add(dr) ;
objdata.Tables. Add(dt);
datagrid1.DataS ource=objdata;
datagrid1.DataB ind();
objdata.WriteXm l(Server.MapPat h("/Secured/XML/"+orderc+".xml" ));
LoadXML();

}

public void doEdit (Object sender, DataGridCommand EventArgs e)
{
datagrid1.EditI temIndex = e.Item.ItemInde x;
LoadXML();
}
public void doCancel(Object sender, DataGridCommand EventArgs e)
{
datagrid1.EditI temIndex = -1;
LoadXML();
}
public void DelXML (object sender, DataGridCommand EventArgs e)
{
orderc = user.SelectedIt em.Value.ToStri ng();
if(e.CommandNam e == "Delete")
{
if(datagrid1.Ed itItemIndex == -1)
{
string x1;
x1 = datagrid1.DataK eys[e.Item.ItemInde x].ToString();
DataSet objdata = new DataSet();
try
{
objdata.ReadXml (Server.MapPath ("OrderGuide s/" + orderc +
".xml"));
objdata.Tables["Product"].DefaultView.Ro wFilter="NAME=' " + x1 +
"'";
if(objdata.Tabl es["Product"].DefaultView.Co unt > 0)
{
objdata.Tables["Product"].DefaultView.De lete(0);
}
objdata.Tables["Product"].DefaultView.Ro wFilter = "";
objdata.WriteXm l(Server.MapPat h("/Secured/XML/"+orderc+".xml" ));

}

catch
{
}
finally
{
CreateXML();
}
LoadXML();
}

}
}
public void doUpdate(Object sender, DataGridCommand EventArgs e)
{
orderc = user.SelectedIt em.Value.ToStri ng();
string N = ((TextBox)e.Ite m.Cells[0].Controls[1]).Text;
string S = ((TextBox)e.Ite m.Cells[1].Controls[1]).Text;
string P = ((TextBox)e.Ite m.Cells[2].Controls[1]).Text;
string T = ((TextBox)e.Ite m.Cells[3].Controls[1]).Text;

datagrid1.EditI temIndex = -1;
DataSet ds = CreateDataSourc e();
DataRow row = ds.Tables[0].Rows[e.Item.ItemInde x];

row["NAME"]=N;
row["SKU"]=S;
row["PRICE"]=P;
row["TYPE"]=T;

ds.WriteXml(Ser ver.MapPath("/Secured/XML/"+orderc+".xml" ));

//mygrid.DataSour ce = CreateDataSourc e();
LoadXML();
}

public void doInsert (object sender, DataGridCommand EventArgs e)
{
orderc = user.SelectedIt em.Value.ToStri ng();
if(e.CommandNam e == "doAdd")
{
//string v1;
TextBox tadd1,tadd2,tad d3,tadd4 = new TextBox();
DataSet objdata = new DataSet();
DataRow dr;
objdata.ReadXml (Server.MapPath ("OrderGuide s/" + orderc + ".xml"));
tadd1 = (TextBox)e.Item .FindControl("n ame_add");
tadd2 = (TextBox)e.Item .FindControl("s ku_add");
tadd3 = (TextBox)e.Item .FindControl("p rice_add");
tadd4 = (TextBox)e.Item .FindControl("t ype_add");

if(tadd1.Text != "" && tadd2.Text != "" && tadd3.Text != "" )
{
objdata.Tables["Product"].DefaultView.Ro wFilter="NAME=' " +
tadd1.Text + "'";
if(objdata.Tabl es["Product"].DefaultView.Co unt <= 0)
{
objdata.Tables["Product"].DefaultView.Ro wFilter = "";
dr = objdata.Tables["Product"].NewRow();
dr[0] = tadd1.Text;
dr[1] = tadd2.Text;
dr[2] = tadd3.Text;
dr[3] = tadd4.Text;
objdata.Tables["Product"].Rows.Add(dr);
objdata.WriteXm l(Server.MapPat h("/Secured/XML/"+orderc+".xml" ));
LoadXML();

}
}
}
}

Nov 26 '05 #1
5 2716
You could create a new c# project in VS and than copy the code into the new
files (.cs) than the compiler would complain if it doesn't understand
something. The extention tells it it should contain c# code and not VB.

Also you could just put the functions that do something into a class and use
the VB class in your c# projects (include the dll in references) but than
make sure only to include the functions that do not directly interact with
the GUI, you could pass references to the function, but that I would not do,
instead pass it a dataset.

-Mark
<ma**********@g mail.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
Hello All,
I am stuck on a conversion problem. I am trying to convert my
application which is written in VB.NET to C# because the project I am
working on currently is being written in C#.
I tried my best to convert it, but somehow the app does not work. I am
also not getting any errors when I complie thus, letting me know I am
on the write track. Basically what I want to do is edit,add,delete , and
update an XML file in a DataGrid. Below is my Code in

sub LoadXML
Dim objdata as New DataSet
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer
Try

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"))
datagrid1.Datas ource=objdata
datagrid1.Datab ind()

Catch

CreateXML

End Try
End sub
Sub CreateXML
Dim objdata as New DataSet("Indian Master")
Dim dt as New DataTable("Prod uct")
Dim dr as DataRow
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer

dt.Columns.Add( New DataColumn("NAM E"))
dt.Columns.Add( New DataColumn("SKU "))
dt.Columns.Add( New DataColumn("PRI CE"))
dt.Columns.Add( New DataColumn("TYP E"))

dr=dt.NewRow()
dr(0)="No Data"
dr(1)="No Data"
dr(2)="No Data"
dr(3)="No Data"

dt.Rows.Add(dr)

objdata.Tables. Add(dt)

datagrid1.datas ource=objdata
datagrid1.datab ind()
objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"))

LoadXML()
End Sub
Sub setEditMode(Sen der as Object, E as DataGridCommand EventArgs)

Dim objdata as New DataSet
Dim x1 as string
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"))

x1=datagrid1.Da taKeys.Item(e.I tem.ItemIndex)

objdata.Tables( "Product").Defa ultView.RowFilt er="NAME='" & x1 &
"'"

If objdata.Tables( "Product").Defa ultView.Count>0 Then
error4.visible= "False"
datagrid1.EditI temIndex=E.Item .ItemIndex
datagrid1.showf ooter="false"
LoadXML
Else
error4.visible= "True"
End If
End sub
Sub cancelEdit(send er as Object, E as DataGridCommand EventArgs)
datagrid1.EditI temIndex=-1
datagrid1.showf ooter="true"
error1.visible= "False"
error2.visible= "False"
error3.visible= "False"
error4.visible= "False"
error5.visible= "False"

LoadXML

End sub
Sub DelXML(S as Object, E as DataGridCommand EventArgs)
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer
If e.CommandName=" Delete" Then
If datagrid1.EditI temIndex=-1 Then
error5.visible= "False"
Dim x1 as string

x1=datagrid1.Da taKeys.Item(e.I tem.ItemIndex)

Dim objdata as New DataSet

Try

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"))
objdata.Tables( "Product").Defa ultView.RowFilt er="NAME='" &
x1 & "'"
If objdata.Tables( "Product").Defa ultView.Count>0 Then
objdata.Tables( "Product").Defa ultView.Delete( 0)
End If

objdata.Tables( "Product").Defa ultView.RowFilt er=""
objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"))
Catch
CreateXML
End Try

LoadXML
Else
error5.visible= "True"
End If
End if
End Sub
Sub UpdateXML(s as Object, e as DataGridCommand EventArgs)
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer
If e.CommandName=" Update" Then
Dim str1, str2, str3,v1 as string
Dim txt1,txt2,txt3, txt4 as Textbox
Dim objdata as New DataSet
Dim x1 as string

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"))

v1=e.Item.ItemI ndex

x1=datagrid1.Da taKeys.Item(e.I tem.ItemIndex)

objdata.Tables( "Product").Defa ultView.RowFilt er="NAME='" & x1 &
"'"

If objdata.Tables( "Product").Defa ultView.Count>0 Then
error3.visible= "False"

txt1=e.Item.Fin dControl("name_ edit")
txt2=e.Item.Fin dControl("sku_e dit")
txt3=e.Item.Fin dControl("price _edit")
txt4=e.Item.Fin dControl("type_ edit")
objdata.Tables( "Product").Rows (v1).Item("NAME ")=txt1.Tex t
objdata.Tables( "Product").Rows (v1).Item("SKU" )=txt2.Text
objdata.Tables( "Product").Rows (v1).Item("PRIC E")=txt3.Tex t
objdata.Tables( "Product").Rows (v1).Item("TYPE ")=txt4.Tex t
datagrid1.datas ource=objdata
datagrid1.datab ind()
objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"))

datagrid1.EditI temIndex=-1
LoadXML
datagrid1.showf ooter="true"
Else
error3.visible= "True"
End If
End If
End sub
Sub doInsert(s as Object, E as DataGridCommand EventArgs)
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer

if e.CommandName=" doAdd" Then
Dim v1 as string
Dim tadd1,tadd2,tad d3,tadd4 as Textbox
Dim objdata as New DataSet
Dim dr as DataRow

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"))

tadd1=e.Item.Fi ndControl("name _add")
tadd2=e.Item.Fi ndControl("sku_ add")
tadd3=e.Item.Fi ndControl("pric e_add")
tadd4=e.Item.Fi ndControl("type _add")

Try
'tadd1.text=int 32.parse(tadd1. text)
error2.visible= "false"

If tadd1.text="" Then
' tadd1.Text=""
error2.visible= "true"
End If
Catch
tadd1.text=""
error2.visible= "true"
End Try

If tadd1.Text<>"" and tadd2.Text<>"" and tadd3.Text<>"" Then
objdata.Tables( "Product").Defa ultView.RowFilt er="NAME='" &
tadd1.Text & "'"
If objdata.Tables( "Product").Defa ultView.Count<= 0 Then
error1.visible= "False"
objdata.Tables( "Product").Defa ultView.RowFilt er=""
dr=objdata.Tabl es("Product").N ewRow()

dr(0)=tadd1.Tex t
dr(1)=tadd2.Tex t
dr(2)=tadd3.Tex t
dr(3)=tadd4.Tex t
objdata.Tables( "Product").Rows .Add(dr)
objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"))
LoadXML
Else
error1.visible= "True"
error1.Text="Pr oduct must be unique"
End If
End If
End If
End Sub

Here is my C# Code:

void LoadXML()
{
DataSet objdata = new DataSet();
orderc = user.SelectedIt em.Value.ToStri ng();
objdata.ReadXml (Server.MapPath ("OrderGuide s/" + orderc + ".xml"));
datagrid1.DataS ource = objdata;
datagrid1.DataB ind();

}

private DataSet CreateDataSourc e()
{
XmlDataDocument mydata = new XmlDataDocument ();
orderc = user.SelectedIt em.Value.ToStri ng();
mydata.DataSet. ReadXml(Server. MapPath("OrderG uides/" + orderc +
".xml"));
return mydata.DataSet;
}
void CreateXML()
{
DataSet objdata = new DataSet("Indian Master");
DataTable dt = new DataTable("Prod uct");
DataRow dr;
orderc = user.SelectedIt em.Value.ToStri ng();
dt.Columns.Add( "NAME");
dt.Columns.Add( "SKU");
dt.Columns.Add( "PRICE");
dt.Columns.Add( "TYPE");
dr = dt.NewRow();
dr[0] = "No Data";
dr[1] = "No Data";
dr[2] = "No Data";
dr[3] = "No Data";
dt.Rows.Add(dr) ;
objdata.Tables. Add(dt);
datagrid1.DataS ource=objdata;
datagrid1.DataB ind();
objdata.WriteXm l(Server.MapPat h("/Secured/XML/"+orderc+".xml" ));
LoadXML();

}

public void doEdit (Object sender, DataGridCommand EventArgs e)
{
datagrid1.EditI temIndex = e.Item.ItemInde x;
LoadXML();
}
public void doCancel(Object sender, DataGridCommand EventArgs e)
{
datagrid1.EditI temIndex = -1;
LoadXML();
}
public void DelXML (object sender, DataGridCommand EventArgs e)
{
orderc = user.SelectedIt em.Value.ToStri ng();
if(e.CommandNam e == "Delete")
{
if(datagrid1.Ed itItemIndex == -1)
{
string x1;
x1 = datagrid1.DataK eys[e.Item.ItemInde x].ToString();
DataSet objdata = new DataSet();
try
{
objdata.ReadXml (Server.MapPath ("OrderGuide s/" + orderc +
".xml"));
objdata.Tables["Product"].DefaultView.Ro wFilter="NAME=' " + x1 +
"'";
if(objdata.Tabl es["Product"].DefaultView.Co unt > 0)
{
objdata.Tables["Product"].DefaultView.De lete(0);
}
objdata.Tables["Product"].DefaultView.Ro wFilter = "";
objdata.WriteXm l(Server.MapPat h("/Secured/XML/"+orderc+".xml" ));

}

catch
{
}
finally
{
CreateXML();
}
LoadXML();
}

}
}
public void doUpdate(Object sender, DataGridCommand EventArgs e)
{
orderc = user.SelectedIt em.Value.ToStri ng();
string N = ((TextBox)e.Ite m.Cells[0].Controls[1]).Text;
string S = ((TextBox)e.Ite m.Cells[1].Controls[1]).Text;
string P = ((TextBox)e.Ite m.Cells[2].Controls[1]).Text;
string T = ((TextBox)e.Ite m.Cells[3].Controls[1]).Text;

datagrid1.EditI temIndex = -1;
DataSet ds = CreateDataSourc e();
DataRow row = ds.Tables[0].Rows[e.Item.ItemInde x];

row["NAME"]=N;
row["SKU"]=S;
row["PRICE"]=P;
row["TYPE"]=T;

ds.WriteXml(Ser ver.MapPath("/Secured/XML/"+orderc+".xml" ));

//mygrid.DataSour ce = CreateDataSourc e();
LoadXML();
}

public void doInsert (object sender, DataGridCommand EventArgs e)
{
orderc = user.SelectedIt em.Value.ToStri ng();
if(e.CommandNam e == "doAdd")
{
//string v1;
TextBox tadd1,tadd2,tad d3,tadd4 = new TextBox();
DataSet objdata = new DataSet();
DataRow dr;
objdata.ReadXml (Server.MapPath ("OrderGuide s/" + orderc + ".xml"));
tadd1 = (TextBox)e.Item .FindControl("n ame_add");
tadd2 = (TextBox)e.Item .FindControl("s ku_add");
tadd3 = (TextBox)e.Item .FindControl("p rice_add");
tadd4 = (TextBox)e.Item .FindControl("t ype_add");

if(tadd1.Text != "" && tadd2.Text != "" && tadd3.Text != "" )
{
objdata.Tables["Product"].DefaultView.Ro wFilter="NAME=' " +
tadd1.Text + "'";
if(objdata.Tabl es["Product"].DefaultView.Co unt <= 0)
{
objdata.Tables["Product"].DefaultView.Ro wFilter = "";
dr = objdata.Tables["Product"].NewRow();
dr[0] = tadd1.Text;
dr[1] = tadd2.Text;
dr[2] = tadd3.Text;
dr[3] = tadd4.Text;
objdata.Tables["Product"].Rows.Add(dr);
objdata.WriteXm l(Server.MapPat h("/Secured/XML/"+orderc+".xml" ));
LoadXML();

}
}
}
}

Nov 26 '05 #2
> Hello All,
I am stuck on a conversion problem. I am trying to convert my
application which is written in VB.NET to C# because the project I am
working on currently is being written in C#.

Go to http://www.aisto.com/roeder/dotnet/ and download Lutz Roeder's excellent
Reflector application. Load your compiled VB.NET assembly and decompile it
to C#.

Anders Norås
http://dotnetjunkies.com/weblog/anoras
Nov 26 '05 #3
How accurate is this application? Also, is there a better way to do it,
instead of decompilers? I want to make sure that I understand each line
of converted code.

Nov 27 '05 #4
Here is the literal source code translation produced with our Instant C# VB
to C# converter (it's possible to produce this translation one method at a
time with our demo). One note: you were setting many boolean values to
string literals "true" and "false" - this is very unorthodox (I've never seen
this before - why not use True and False ?) and they are left as string
literals - you'll have to change that manually.

public void LoadXML()
{
DataSet objdata = new DataSet();
string customer = null;
customer = CustomerDropDow n.SelectedItem. Value.ToString( );
temp.Text = customer;
try
{

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"));
datagrid1.DataS ource=objdata;
datagrid1.DataB ind();

}
catch
{

CreateXML();

}
}
public void CreateXML()
{
DataSet objdata = new DataSet("Indian Master");
DataTable dt = new DataTable("Prod uct");
DataRow dr = null;
string customer = null;
customer = CustomerDropDow n.SelectedItem. Value.ToString( );
temp.Text = customer;

dt.Columns.Add( new DataColumn("NAM E"));
dt.Columns.Add( new DataColumn("SKU "));
dt.Columns.Add( new DataColumn("PRI CE"));
dt.Columns.Add( new DataColumn("TYP E"));

dr=dt.NewRow();
dr[0]="No Data";
dr[1]="No Data";
dr[2]="No Data";
dr[3]="No Data";

dt.Rows.Add(dr) ;

objdata.Tables. Add(dt);

datagrid1.DataS ource=objdata;
datagrid1.DataB ind();
objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"));

LoadXML();
}
public void setEditMode(obj ect Sender, DataGridCommand EventArgs E)
{

DataSet objdata = new DataSet();
string x1 = null;
string customer = null;
customer = CustomerDropDow n.SelectedItem. Value.ToString( );
temp.Text = customer;

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"));

x1=datagrid1.Da taKeys[E.Item.ItemInde x];

objdata.Tables["Product"].DefaultView.Ro wFilter="NAME=' " + x1 + "'";

if (objdata.Tables["Product"].DefaultView.Co unt>0)
{
error4.Visible= "False";
datagrid1.EditI temIndex=E.Item .ItemIndex;
datagrid1.showf ooter="false";
LoadXML();
}
else
error4.Visible= "True";
}
public void cancelEdit(obje ct sender, DataGridCommand EventArgs E)
{
datagrid1.EditI temIndex=-1;
datagrid1.showf ooter="true";
error1.Visible= "False";
error2.Visible= "False";
error3.Visible= "False";
error4.Visible= "False";
error5.Visible= "False";

LoadXML();

}
public void DelXML(object S, DataGridCommand EventArgs E)
{
string customer = null;
customer = CustomerDropDow n.SelectedItem. Value.ToString( );
temp.Text = customer;
if (E.CommandName= ="Delete")
{
if (datagrid1.Edit ItemIndex==-1)
{
error5.Visible= "False";
string x1 = null;

x1=datagrid1.Da taKeys[E.Item.ItemInde x];

DataSet objdata = new DataSet();

try
{

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"));
objdata.Tables["Product"].DefaultView.Ro wFilter="NAME=' " + x1 + "'";
if (objdata.Tables["Product"].DefaultView.Co unt>0)
objdata.Tables["Product"].DefaultView.De lete(0);

objdata.Tables["Product"].DefaultView.Ro wFilter="";
objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"));
}
catch
{
CreateXML();
}

LoadXML();
}
else
error5.Visible= "True";
}
}
public void UpdateXML(objec t s, DataGridCommand EventArgs e)
{
string customer = null;
customer = CustomerDropDow n.SelectedItem. Value.ToString( );
temp.Text = customer;
if (e.CommandName= ="Update")
{
string str1 = null;
string str2 = null;
string str3 = null;
string v1 = null;
TextBox txt1 = null;
TextBox txt2 = null;
TextBox txt3 = null;
TextBox txt4 = null;
DataSet objdata = new DataSet();
string x1 = null;

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"));

v1=e.Item.ItemI ndex;

x1=datagrid1.Da taKeys[e.Item.ItemInde x];

objdata.Tables["Product"].DefaultView.Ro wFilter="NAME=' " + x1 + "'";

if (objdata.Tables["Product"].DefaultView.Co unt>0)
{
error3.Visible= "False";

txt1=e.Item.Fin dControl("name_ edit");
txt2=e.Item.Fin dControl("sku_e dit");
txt3=e.Item.Fin dControl("price _edit");
txt4=e.Item.Fin dControl("type_ edit");
objdata.Tables["Product"].Rows[v1]["NAME"]=txt1.Text;
objdata.Tables["Product"].Rows[v1]["SKU"]=txt2.Text;
objdata.Tables["Product"].Rows[v1]["PRICE"]=txt3.Text;
objdata.Tables["Product"].Rows[v1]["TYPE"]=txt4.Text;
datagrid1.DataS ource=objdata;
datagrid1.DataB ind();

objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"));

datagrid1.EditI temIndex=-1;
LoadXML();
datagrid1.showf ooter="true";
}
else
error3.Visible= "True";
}
}
public void doInsert(object s, DataGridCommand EventArgs E)
{
string customer = null;
customer = CustomerDropDow n.SelectedItem. Value.ToString( );
temp.Text = customer;

if (E.CommandName= ="doAdd")
{
string v1 = null;
TextBox tadd1 = null;
TextBox tadd2 = null;
TextBox tadd3 = null;
TextBox tadd4 = null;
DataSet objdata = new DataSet();
DataRow dr = null;

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"));

tadd1=E.Item.Fi ndControl("name _add");
tadd2=E.Item.Fi ndControl("sku_ add");
tadd3=E.Item.Fi ndControl("pric e_add");
tadd4=E.Item.Fi ndControl("type _add");

try
{
//tadd1.text=int3 2.parse(tadd1.t ext)
error2.Visible= "false";

if (tadd1.Text=="" )
{
// tadd1.Text=""
error2.Visible= "true";
}
}
catch
{
tadd1.Text="";
error2.Visible= "true";
}

if (tadd1.Text!="" & tadd2.Text!="" & tadd3.Text!="")
{
objdata.Tables["Product"].DefaultView.Ro wFilter="NAME=' " + tadd1.Text +
"'";
if (objdata.Tables["Product"].DefaultView.Co unt<=0)
{
error1.Visible= "False";
objdata.Tables["Product"].DefaultView.Ro wFilter="";
dr=objdata.Tabl es["Product"].NewRow();

dr[0]=tadd1.Text;
dr[1]=tadd2.Text;
dr[2]=tadd3.Text;
dr[3]=tadd4.Text;
objdata.Tables["Product"].Rows.Add(dr);

objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"));
LoadXML();
}
else
{
error1.Visible= "True";
error1.Text="Pr oduct must be unique";
}
}
}
}

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter

"ma**********@g mail.com" wrote:
Hello All,
I am stuck on a conversion problem. I am trying to convert my
application which is written in VB.NET to C# because the project I am
working on currently is being written in C#.
I tried my best to convert it, but somehow the app does not work. I am
also not getting any errors when I complie thus, letting me know I am
on the write track. Basically what I want to do is edit,add,delete , and
update an XML file in a DataGrid. Below is my Code in

sub LoadXML
Dim objdata as New DataSet
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer
Try

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"))
datagrid1.Datas ource=objdata
datagrid1.Datab ind()

Catch

CreateXML

End Try
End sub
Sub CreateXML
Dim objdata as New DataSet("Indian Master")
Dim dt as New DataTable("Prod uct")
Dim dr as DataRow
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer

dt.Columns.Add( New DataColumn("NAM E"))
dt.Columns.Add( New DataColumn("SKU "))
dt.Columns.Add( New DataColumn("PRI CE"))
dt.Columns.Add( New DataColumn("TYP E"))

dr=dt.NewRow()
dr(0)="No Data"
dr(1)="No Data"
dr(2)="No Data"
dr(3)="No Data"

dt.Rows.Add(dr)

objdata.Tables. Add(dt)

datagrid1.datas ource=objdata
datagrid1.datab ind()
objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"))

LoadXML()
End Sub
Sub setEditMode(Sen der as Object, E as DataGridCommand EventArgs)

Dim objdata as New DataSet
Dim x1 as string
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"))

x1=datagrid1.Da taKeys.Item(e.I tem.ItemIndex)

objdata.Tables( "Product").Defa ultView.RowFilt er="NAME='" & x1 &
"'"

If objdata.Tables( "Product").Defa ultView.Count>0 Then
error4.visible= "False"
datagrid1.EditI temIndex=E.Item .ItemIndex
datagrid1.showf ooter="false"
LoadXML
Else
error4.visible= "True"
End If
End sub
Sub cancelEdit(send er as Object, E as DataGridCommand EventArgs)
datagrid1.EditI temIndex=-1
datagrid1.showf ooter="true"
error1.visible= "False"
error2.visible= "False"
error3.visible= "False"
error4.visible= "False"
error5.visible= "False"

LoadXML

End sub
Sub DelXML(S as Object, E as DataGridCommand EventArgs)
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer
If e.CommandName=" Delete" Then
If datagrid1.EditI temIndex=-1 Then
error5.visible= "False"
Dim x1 as string

x1=datagrid1.Da taKeys.Item(e.I tem.ItemIndex)

Dim objdata as New DataSet

Try

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"))
objdata.Tables( "Product").Defa ultView.RowFilt er="NAME='" &
x1 & "'"
If objdata.Tables( "Product").Defa ultView.Count>0 Then
objdata.Tables( "Product").Defa ultView.Delete( 0)
End If

objdata.Tables( "Product").Defa ultView.RowFilt er=""
objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"))
Catch
CreateXML
End Try

LoadXML
Else
error5.visible= "True"
End If
End if
End Sub
Sub UpdateXML(s as Object, e as DataGridCommand EventArgs)
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer
If e.CommandName=" Update" Then
Dim str1, str2, str3,v1 as string
Dim txt1,txt2,txt3, txt4 as Textbox
Dim objdata as New DataSet
Dim x1 as string

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"))

v1=e.Item.ItemI ndex

x1=datagrid1.Da taKeys.Item(e.I tem.ItemIndex)

objdata.Tables( "Product").Defa ultView.RowFilt er="NAME='" & x1 &
"'"

If objdata.Tables( "Product").Defa ultView.Count>0 Then
error3.visible= "False"

txt1=e.Item.Fin dControl("name_ edit")
txt2=e.Item.Fin dControl("sku_e dit")
txt3=e.Item.Fin dControl("price _edit")
txt4=e.Item.Fin dControl("type_ edit")
objdata.Tables( "Product").Rows (v1).Item("NAME ")=txt1.Tex t
objdata.Tables( "Product").Rows (v1).Item("SKU" )=txt2.Text
objdata.Tables( "Product").Rows (v1).Item("PRIC E")=txt3.Tex t
objdata.Tables( "Product").Rows (v1).Item("TYPE ")=txt4.Tex t
datagrid1.datas ource=objdata
datagrid1.datab ind()
objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"))

datagrid1.EditI temIndex=-1
LoadXML
datagrid1.showf ooter="true"
Else
error3.visible= "True"
End If
End If
End sub
Sub doInsert(s as Object, E as DataGridCommand EventArgs)
Dim customer as String
customer = CustomerDropDow n.SelectedItem. Value.ToString
temp.Text = customer

if e.CommandName=" doAdd" Then
Dim v1 as string
Dim tadd1,tadd2,tad d3,tadd4 as Textbox
Dim objdata as New DataSet
Dim dr as DataRow

objdata.ReadXML (Server.Mappath ("/Secured/XML/"+customer+".xm l"))

tadd1=e.Item.Fi ndControl("name _add")
tadd2=e.Item.Fi ndControl("sku_ add")
tadd3=e.Item.Fi ndControl("pric e_add")
tadd4=e.Item.Fi ndControl("type _add")

Try
'tadd1.text=int 32.parse(tadd1. text)
error2.visible= "false"

If tadd1.text="" Then
' tadd1.Text=""
error2.visible= "true"
End If
Catch
tadd1.text=""
error2.visible= "true"
End Try

If tadd1.Text<>"" and tadd2.Text<>"" and tadd3.Text<>"" Then
objdata.Tables( "Product").Defa ultView.RowFilt er="NAME='" &
tadd1.Text & "'"
If objdata.Tables( "Product").Defa ultView.Count<= 0 Then
error1.visible= "False"
objdata.Tables( "Product").Defa ultView.RowFilt er=""
dr=objdata.Tabl es("Product").N ewRow()

dr(0)=tadd1.Tex t
dr(1)=tadd2.Tex t
dr(2)=tadd3.Tex t
dr(3)=tadd4.Tex t
objdata.Tables( "Product").Rows .Add(dr)
objdata.WriteXM L(Server.mappat h("/Secured/XML/"+customer+".xm l"))
LoadXML
Else
error1.visible= "True"
error1.Text="Pr oduct must be unique"
End If
End If
End If
End Sub

Here is my C# Code:

void LoadXML()
{
DataSet objdata = new DataSet();
orderc = user.SelectedIt em.Value.ToStri ng();
objdata.ReadXml (Server.MapPath ("OrderGuide s/" + orderc + ".xml"));
datagrid1.DataS ource = objdata;
datagrid1.DataB ind();

}

private DataSet CreateDataSourc e()
{
XmlDataDocument mydata = new XmlDataDocument ();
orderc = user.SelectedIt em.Value.ToStri ng();
mydata.DataSet. ReadXml(Server. MapPath("OrderG uides/" + orderc +
".xml"));
return mydata.DataSet;
}
void CreateXML()
{
DataSet objdata = new DataSet("Indian Master");
DataTable dt = new DataTable("Prod uct");
DataRow dr;
orderc = user.SelectedIt em.Value.ToStri ng();
dt.Columns.Add( "NAME");
dt.Columns.Add( "SKU");
dt.Columns.Add( "PRICE");
dt.Columns.Add( "TYPE");
dr = dt.NewRow();
dr[0] = "No Data";
dr[1] = "No Data";
dr[2] = "No Data";
dr[3] = "No Data";
dt.Rows.Add(dr) ;
objdata.Tables. Add(dt);
datagrid1.DataS ource=objdata;
datagrid1.DataB ind();
objdata.WriteXm l(Server.MapPat h("/Secured/XML/"+orderc+".xml" ));
LoadXML();

}

public void doEdit (Object sender, DataGridCommand EventArgs e)
{
datagrid1.EditI temIndex = e.Item.ItemInde x;
LoadXML();
}

Nov 27 '05 #5
Thanks David...
I will take a look at your code and compare it too mine.

Thanks agian for your help.

Nov 28 '05 #6

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

Similar topics

7
3296
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte buffer into the character pointer. The code looks like the following: #include <stdio.h> #include <stdlib.h> #include "stdafx.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call,
5
2385
by: MFC | last post by:
Ok, after three C# books, (C# How to Program, Programming in the Key of C#, and C# Weekend Crash Course) and three weeks, I believe I have tried everything to make a certain form function correctly. I am trying to learn C# after playing around for a bit with procedural programming with PHP, not OOP, and believe I have learned quite a bit in three weeks, just not enough to accomplish this one task. If anyone has a bit of free time and...
22
1480
by: OHM \( Terry Burns \) | last post by:
I was thinking about community the other day, and wondering what would be the holy grail for a developer in need. I mean, we do get help here, but its done on a best endeavours basis and its really really good most of the time. What Ideally would you guys like to see in the perfect community site which would help you out? -- OHM ( Terry Burns ) * Use the following to email me *
7
1871
by: Charlie Brookhart | last post by:
I have a program (posted below) that is supposed to take liters, which is the user input, and convert it to pints and gallons. The pints and gallons are displayed in a read only textbox. I don't understand how to fix the problem. 'declaring variables Dim totalLiters As Double = Convert.ToDouble(txtLiters.Text) Dim totalPints As Double = Convert.ToDouble(txtPints.Text)
3
326
by: ravi | last post by:
Hi, I am new to C++ .Can anyone please tell me what does ":" operator mean in C++.For ex: there is a program snippet which looks like that class convert { protected: double val1; // initial value double val2; // converted value public: convert(double i) {
11
1850
by: Matthew | last post by:
Ok let me try to explain this as good as I can. I am creating this application where it contains a userlogin class. The user logs in before entering the main apploication. I want to do audit trails and I am trying to figure out how to get the user ID that logged in. Can anyone help me. I have samples if anyone needs them.
16
5438
by: manmit.walia | last post by:
Hello All, I have tried multiple online tools to convert an VB6 (bas) file to VB.NET file and no luck. I was hoping that someone could help me covert this. I am new to the .NET world and still learning all help would be greatly apperciated. Attribute VB_Name = "Module1" Option Explicit
0
2530
by: Pucca | last post by:
Hi I'm using vs2005. I am getting a bunch of compiler warnings after I made some changes to my code that was compiling clean. I'm also getting memory errors when I run my program and it's pinvoking some C++ code, which was working also fine before. I wonder if these warning are causing the problem. I would appreciate some help or suggestions on how to correct these. Thanks. Warning 37 At least one of the arguments for...
8
1910
by: SanjaiGandhi | last post by:
Hi ...i am new to programing....pls help to overcome this program.. The Program is..: if a = 557..using for loop or while or dowhile ..we have to get the answer for 5+5+7..that is what ever numbers we entered to a..that should be added.. for eg if a = 34 the answe should be 7 that is 3+4 using % and / we can solve this problem..pls help me to get the problems
8
2732
by: manmit.walia | last post by:
Hello Everyone, Long time ago, I posted a small problem I had about converting a VB6 program to C#. Well with the help with everyone I got it converted. But I overlooked something and don't understand why it is doing this. Below is my code, I would be greatfull if someone can guide me through the right path or even help me solve this issue. Problem: The old tool which was written in VB6 works perfect. But I needed to convert this to C#...
0
8182
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
8130
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
8627
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...
0
8579
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8279
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4052
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
4127
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2568
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
0
1425
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.