|
|
Ashfield is right, there are plenty of articles on this site and on the net, but here is one possible approach (which is working for me, while you read this):
1. make an excel file with some demo data and make it look the way you want your app to make it look.
2. save it as xml
3. open this xml file in vs2003, so you can see what it looks like
4. use some loops to write the values from your dataset and the xml tags into a big string.
5. write the string to an xls file with a StreamWriter
6. Bob's your uncle.
Because you wrote the file as an xml file, it can easily be opened with Excel, OpenOffice or any other program that can usually read Excel files.
Good luck.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Thanx Ashfield and Johan for replying..
I got the problem fixed. What Iv done is that I write the data from Datagrid into CSV file format which then can be opened in both MS Office and Open Office Spreadsheet.
|
|
|
|
|
Hi
I am having a little bit of trouble understanding how to read property values from objects in the Active Directory that are not included in the standard DirectoryServices.AccountManagement namespace which is new in .NET 3.5 ..
At current this is the only reference I have which I am not following.. not a very good C# guy!
http://costoda.blogspot.com/2008/01/getting-information-from-active.html[^]
If someone could suggest some examples on how to do the same as that link above in VB instead that would be awesome!
Kind Regards,
Tim
|
|
|
|
|
Does anyone know anything on this topic? I don't want to sound impatient!
Tim
-------------------------
Visit my Blog:
http://tim.raimes.com.au/
|
|
|
|
|
|
That tool was really useful, especially since it was free as I have seen expensive tools that do similar things! Thanks for that.
Ok So this has helped me build the code into a VB Class.. I am stuggling with implementing the same class into my project.. as it might get confusing to go deeper into the actually code I am working on can someone provide a rough example of how to "get" and "set" values on custom properties constructed in a class. My memory needs refreshing..
Does that make sense?
Tim
-------------------------
Visit my Blog:
http://tim.raimes.com.au/
|
|
|
|
|
|
Hello. I did something that would be considered very stupid to any experienced programmer and now would like to revert to the code in my last successful build. I am able to run the last successful build, how can I move forward in editing the associated code? Is this possible? I am using Visual Basic 2008 Express. My frustration is growing!
- Craig
"That rug really tied the room together."
|
|
|
|
|
Sorry. Not unless you are using some form of source control where you can check out a past version. There are two kinds of people out there. Those that have already experienced what you're going through - and those who will.
Look into using subversion, or some other version control software.
If it's just a small change you need to see, you might can open the old build in Reflector and see if you can get what you need...
|
|
|
|
|
You might want to look at version control tools, such as subversion.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
hai all,
i am new to .net, i have been given a task to create a vb.net app To send an email from the application using smtp gateway. Can anybody help me with this, kindly reply me as soon as possible.
Thanks in advance.
|
|
|
|
|
take a look at the system.net.mail classes
there you can create a Mailmessage and send it with a smtpclient
(you will have to set the host of the smtpclient)
something like
imports system.net.mail
dim msg as new mailmessage(senderemail,recemail,subject,body)
dim client as new smtpclient
client.host="smtpserver"
client.send(msg)
(This is from memory so could be it doesn't compile but it should help you on your way)
|
|
|
|
|
can you please help me out in detail,
i am getting the error message as "Declaration expected", even after i declared them as
Dim senderemail As String
Dim recemail As String
Dim subject As String
Dim body As String
Dim msg As New MailMessage(senderemail, recemail, subject, body)
Dim client As New SmtpClient
Do i need to add any other classes to make it work
thank you for your reply.Kindly please guide me through this also.
Waiting for reply.
|
|
|
|
|
Do a search on this site or on google. You will find 100s of tutorials about this subject.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
|
|
|
|
|
try typing the entire path to the class I seem to remeber having to do that too
dim msg as new system.net.mail.mailmessage
dim client as new system.net.mail.smtpclient
|
|
|
|
|
Thanks Tom, i was able to do it.
|
|
|
|
|
I tried to make a simple application using VB.NET that is able to import excel data into sql. I got some tutorial from Bytes Forum. I've tried to follow the instruction to check msexcl40.dll, it's there but I still got an error said that the program could not find installable ISAM. Can someone help me?
Private Function frmUploader_upload() As Boolean<br />
Dim strConnection As String<br />
Dim strCommand As String<br />
Dim excelConnection As System.Data.OleDb.OleDbConnection<br />
Dim excelCommand As System.Data.OleDb.OleDbCommand<br />
<br />
strConnection = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}; Extended Properties=Excel 8.0;Persist Security Info=False", Me.tbFile.Text)<br />
excelConnection = New System.Data.OleDb.OleDbConnection(strConnection)<br />
strCommand = "INSERT INTO [OBDC; Driver={SQL Server}; Server=" & Me.tbServer.Text & "; Database=" & Me.tbDatabase.Text & "; Trusted_Connection=yes].[Sl_Logproof_200311] SELECT * FROM [" & Me.cbSheet.Text & "$];"<br />
excelCommand = New System.Data.OleDb.OleDbCommand(strCommand, excelConnection)<br />
<br />
Try<br />
excelConnection.Open()<br />
excelCommand.ExecuteNonQuery() 'got error after this line<br />
Catch ex As Exception<br />
MsgBox(ex.Message)<br />
Return False<br />
Finally<br />
excelConnection.Close()<br />
End Try<br />
<br />
Return True<br />
End Function
Best Regard,
Indra Permana Rusli
|
|
|
|
|
Looks like you are totally mixed up. This connection works for me
OleDbConnection con = new OleDbConnection(string.Format("Data Source={0};Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;", excelfileName));
and your insert is total rubbish as far as I can see. Try something like this
sqlToRun= string.Format("insert into mytable(mycolumn1,mycolumn2) values ('{0}','{1}'",val1,val2);
cmd = new OleDbCommand(sqlToRun, con);
cmd.ExecuteNonQuery();
Hope this helps.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Sorry, you'll have to convert from C#
Bob
Ashfield Consultants Ltd
|
|
|
|
|
That can't be too hard to do
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I tried to follow your code and modified it with a data reader.
Public Function ExecuteQuery(ByVal query As String) As Boolean
Dim con As System.Data.OleDb.OleDbConnection
Dim cmd As System.Data.OleDb.OleDbCommand
con = New System.Data.OleDb.OleDbConnection(DSN)
cmd = New System.Data.OleDb.OleDbCommand(query, con)
cmd.CommandType = CommandType.Text
Try
con.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Throw ex
Finally
con.Close()
End Try
Return True
End Function
Private Function frmUploader_upload() As Boolean
Dim strConnection As String
Dim strCommand As String
Dim query As String
Dim excelConnection As System.Data.OleDb.OleDbConnection
Dim excelCommand As System.Data.OleDb.OleDbCommand
Dim dr As System.Data.OleDb.OleDbDataReader
Dim dt As New DataTable
Dim i As Integer = 0
strConnection = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}; Extended Properties=Excel 8.0;Persist Security Info=False", Me.tbFile.Text)
excelConnection = New System.Data.OleDb.OleDbConnection(strConnection)
strCommand = String.Format("SELECT * FROM [{0}$]", Me.cbSheet.Text)
excelCommand = New System.Data.OleDb.OleDbCommand(strCommand, excelConnection)
Try
excelConnection.Open()
dr = excelCommand.ExecuteReader
While dr.Read
query = String.Format("INSERT INTO Sl_Logproof_200311 VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}',{18},{19},{20},{21},'{22}',{23},{24},'{25}','{26}','{27}',{28})", _
ReplaceQuote(dr(0).ToString), ReplaceQuote(dr(1).ToString), ReplaceQuote(dr(2).ToString), ReplaceQuote(dr(3).ToString), ReplaceQuote(dr(4).ToString), ReplaceQuote(dr(5).ToString), ReplaceQuote(dr(6).ToString), ReplaceQuote(dr(7).ToString), ReplaceQuote(dr(8).ToString), ReplaceQuote(dr(9).ToString), ReplaceQuote(dr(10).ToString), _
ReplaceQuote(dr(11).ToString), ReplaceQuote(dr(12).ToString), ReplaceQuote(dr(13).ToString), ReplaceQuote(dr(14).ToString), ReplaceQuote(dr(15).ToString), ReplaceQuote(dr(16).ToString), ReplaceQuote(dr(17).ToString), IsEmptyText(dr(18).ToString, "0"), IsEmptyText(dr(19).ToString, "0"), IsEmptyText(dr(20).ToString, "0"), _
IsEmptyText(dr(21).ToString, "0"), ReplaceQuote(dr(22).ToString), IsEmptyText(dr(23).ToString, "0"), IsEmptyText(dr(24).ToString, "0"), ReplaceQuote(dr(25).ToString), ReplaceQuote(dr(26).ToString), ReplaceQuote(dr(28).ToString), ReplaceQuote(dr(27).ToString))
ExecuteQuery(query)
If i Mod 1000 = 0 Then
Me.tsStatus.Text = String.Format("{0} Rows have been transformed or copied.", i)
End If
i += 1
End While
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
excelConnection.Close()
End Try
Return True
End Function
It can copy now, but is there any better way? With this code, it still takes too much time to import and it needs 2 connections. Using SQL Server DTS is a lot faster.
Best Regards,
Indra Permana Rusli
|
|
|
|
|
Well, yes DTS is a lot quicker, thats what it was designed for! You may be able to tweak your code, but I doubt if it will ever outperform dts.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hohohoho, thanks, finally I can import it well using DTS. I am using Microsoft DTS Custom Task Object Library reference in my source code and create DTS Package with a global variable named gvDataSource in the SQL Server. Then here is my new code.
Private Function frmUploader_upload() As Boolean
Dim pkg As DTS.Package2
pkg = New DTS.Package
pkg.LoadFromSQLServer(mDBSERVER, mDBUSER, mDBPASSWORD, DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, , , , "APLIKASI3:E_START.Sl_Logproof_200311")
For Each gv As DTS.GlobalVariable In pkg.GlobalVariables
pkg.GlobalVariables.Remove(gv.Name)
Next
pkg.GlobalVariables.AddGlobalVariable("gvDataSource", Me.tbFile.Text)
Me.Cursor = Cursors.WaitCursor
Try
pkg.Execute()
Catch ex As Exception
MsgBox(ex.Message)
Return False
Finally
pkg.UnInitialize()
pkg = Nothing
End Try
Me.Cursor = Cursors.Default
Return True
End Function
Best Regard,
Indra Permana Rusli
|
|
|
|
|
pleased to be of some use.
Bob
Ashfield Consultants Ltd
|
|
|
|
|