Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB TO C# need help

Status
Not open for further replies.

RaulMA

Programmer
Apr 4, 2006
19
US
Can some one help me to change this vb code to c#. What it does is to read an xml file an store data into sql server database.

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes

Module Module1

Sub Main()
Dim objSQLConn As New SqlConnection("Server=TEST\\NETSDK;UID=sa;PWD=us;Database=Professional")

Dim objAdapter As SqlDataAdapter

Dim objDataRow, objDBRow As DataRow

Dim objDSXML As New DataSet()

Dim objDSDBTable As New DataSet("tblBooks")

Dim ObjCmdBuilder As SqlCommandBuilder

objDSXML.ReadXml("C:\TEST.xml")

objSQLConn.Open()

objAdapter = New SqlDataAdapter("select Sector,SubSector from Categories", objSQLConn)

objAdapter.Fill(objDSDBTable, "tblBooks")
For Each objDataRow In objDSXML.Tables(0).Rows
Next

With objDSDBTable.Tables(0)

objDBRow = .NewRow()

objDBRow(0) = objDataRow(0)

objDBRow(1) = objDataRow(1)


.Rows.Add(objDBRow)

End With
ObjCmdBuilder = New SqlCommandBuilder(objAdapter)

End Sub
End Module
 
I don't think anyone in here is going to write this code for you but for starters, you use using statements instead of imports...to declare variables you preface the variable name with it's object type...SqlDataAdapter objAdapter...

That should get you started.

The wisest people are those who are smart enough to realize they don't know it all.
 
You can also use a tool like Reflector to change the IL code in your VB.NET assembly to C#. It won't be pretty, but it'll be functionally equivalent.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top