|
|
Hi yyyyyy87.
The client need have the SQL Native Client Installed.
SINCERELY.
ANTHONY ACUÑA
PREFERED PHRASE:
SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?
|
|
|
|
|
Hi.
Last week I posted a question regarding reading Excel file and loading it into the DataGrid.
I didn't get any useful response back so please forgive me for posting this second time.
I'm sure someone had the same problem I have.
I have 3 columns in Excel. One of the columns (User Id) has text data (like: User 1) or a number data (like: 12345). My code works and doesn't throw any error but for some reason it only extracts text data. The numbers are missing and I'm not sure why. I've tried to foramt that columnt to TEXT only but it doesn't help. Just to be sure I looped through DataSet to make sure the values are there and of course they weren't.
Here's the code that reads Excel and loads data into DataGrid. Please help.
Thank you.
Try<br />
'Create DataSet and DataAdapter<br />
ds = New System.Data.DataSet<br />
da = New System.Data.OleDb.OleDbDataAdapter<br />
<br />
'Establish connection<br />
con = New System.Data.OleDb.OleDbConnection( _<br />
"provider=Microsoft.Jet.OLEDB.4.0; " & _<br />
"data source=" & Session("ExcelFilePath").ToString() & "; " & _<br />
"Extended Properties=Excel 8.0")<br />
<br />
'Create command<br />
cmdSelectExcel = New System.Data.OleDb.OleDbCommand("SELECT * FROM [Sheet1$] ORDER BY Company", con)<br />
<br />
'Open connection<br />
con.Open()<br />
<br />
'Exectue command through adapter<br />
da.SelectCommand = cmdSelectExcel<br />
da.Fill(ds, "[Sheet1$]")<br />
<br />
'Assign DataSourse of the DataGrid and bind it<br />
dg.DataSource = ds.Tables(0).DefaultView<br />
dg.DataBind()<br />
<br />
'Close Connection<br />
con.Close()<br />
Catch ex As Exception<br />
'Display error message<br />
lblError.Text = "Error: " & ex.ToString()<br />
lblError.Visible = True<br />
End Try
|
|
|
|
|
Hi Alexfromto.
Do you want that the oledb driver extracts all data as Text, correctly?
Then you need add the follow Extended Properties:
1st: IMEX=1;
2nd: MaxScanRows=0
The first property force the OleDb Driver to read any cell of excel for determine the column type.
The second establish the number of cell for every column to scan for determine de column type, the 0 value force to scan all cells.
SINCERELY.
ANTHONY ACUÑA
PREFERED PHRASE:
SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?
|
|
|
|
|
Thank you very much Anthony. It worked like a charm. You da man.
Alex.
|
|
|
|
|
I am new to "The Code Project".
I was attracted to this site due to an article; "Advanced DataGrid Formating with ItemDataBound".
The article identified how to format ADO.Net Datagrid rows conditionally.
I need to do the same from a VB.Net Datagrid.
My Application provides the user a datagrid that displays equipment calibration related data. I.E. "Equip. Serial #", "Due dates" ETC...
I want to conditionally change the color of rows (records) who's "Due date" columns are greater than the current date; DueDate > Today()
Thus, visually identifing records which need to be prioritized.
Can anyone direct me to an article, or perhaps point me in the right direction?
Regards:
DDscales
DDscales
|
|
|
|
|
Hi DDscales.
Try Using
[c#]
this.dataGridView1.Rows[0].DefaultCellStyle
Or if you are using the a DataSet use DataBindings to set the properties with the correct datamember.
SINCERELY.
ANTHONY ACUÑA
PREFERED PHRASE:
SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?
|
|
|
|
|
Perhaps I am just to green.
I assume "this." refers to my DataGrid "DataGrid1" ?
Also, I notice in your reply [c#], I am running VB 2003. Or does that matter?
Anyway...I think my problem is I do not know how to set the dataGridView properties. Do I have to create a class Library?
I realize this could get rather complicated. Could you refer me to an article or virtual lab that might help me to get the answers?
Regards:
DDscales
|
|
|
|
|
I have a function that needs to be called anytime the form is re-sized, minimized or maximized. In VB6, I could just set the AutoRefresh and call the function in the resize routine and everything worked fine. It doesn't seem to work that way in VB.NET. Any ideas?
Thanks,
Tim Alvord
|
|
|
|
|
There's an event for the form resizing, and another, I believe, for if the state is changed.
|
|
|
|
|
A user, Craig Gemmill, on another forum solved it this way. It's pretty slick:
Private Sub frmJournal_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SetStyle(ControlStyles.UserPaint, True)
SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
SetStyle(ControlStyles.ResizeRedraw, True)
Me.UpdateStyles()
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Using gradientBrush As New Drawing2D.LinearGradientBrush(Me.ClientRectangle, Color.Black, Color.Blue, Drawing2D.LinearGradientMode.Vertical)
e.Graphics.FillRectangle(gradientBrush, Me.ClientRectangle)
End Using
End Sub
Tim Alvord
|
|
|
|
|
I'm not sure if this is possible....but I was wondering if it is it possible to set properties (like set different font styles/font sizes) to items within a listbox or combobox. Any help woud be greatly appreciated, thank you in advance!
|
|
|
|
|
No, you need to create an owner drawn listbox to do this ( or look for one on the site )
|
|
|
|
|
Thank you very much, I'll try that.
|
|
|
|
|
I need to know how to make sure a row is numeric when written to the database. Here is some sample code:
FormatCost = Format(CSng(row("dealernetpricedollars")), "c").ToString()
Thanks!
jds1207
|
|
|
|
|
|
Ok. What do I use if the row is not numeric?
|
|
|
|
|
You asked how to know if the value is numeric... since the question was posed in a VB forum, the answer given is the function to test a value in VB.
How the application handles this is another question entirely and beyond the scope of the first question.
|
|
|
|
|
FormatCost = Format(CSng(row("dealernetpricedollars")), "c").ToString()
If isNumeric(FormatCost) = True Then
' Some Code to handle True Condition
Else
' Some code to handle False Condition
End If
DDscales
|
|
|
|
|
I want to take control of installed printers on my computer (network) and from any computer on the network, send data directly for printing.
Could anyone help with some concepts and example code?
omo code
|
|
|
|
|
First, the disclaimer: I have ZERO experience with VB. However, I have been tasked with writing some code for some intensive calculations using VB in Excel. I have discovered that to write data from an array to the Excel worksheet, you can use the following:
Worksheets("Sheet2").Range("A2").Resize(1, UpperLimit).Value = ConvDataEuro
Where UpperLimit is the size of the row and ConvDataEuro is the array holding my data. However, I need to write in excess of 400 array elements and the row limit on Excel is 256. Thus, I want to write the data in columns rather than rows. Unfortunately, this is apparently not easy to do as I have spent the last hour trying to do this with zero success.
So, my question is: how do I take array data and write it to a column in Excel instead of a row? This should be simple, but under VB in Excel it is not intuitive.
TIA.
|
|
|
|
|
1. This is not truly a VB question; it is an Excel question. All languages will be constrained by the object model.
2. Played with the VBA briefly: reverse your resize parameters (UpperLimit, 1)... that appears to work.
YWIA.
Tim
|
|
|
|
|
Hi Tim,
Thanks for the help. I tried switching the limits and what it does is that it prints out an entire column length of the first entry of the array. I managed to get it to work using an alternate method (I am sure, however that there is a better way) whereby I loop through the array and print out each element of the array while incrementing the spreadsheet cell. Like I said, I am sure there is a better/more efficient way of doing this.
Thanks for the answer though - when I have some free time I'll try again.
Also, where else was I to post the question, the Lounge perhaps?
|
|
|
|
|
I have no problem with the question being posed here... and posting it in the Lounge or Soapbox would have resulted in a flaming...
I don't like to use Excel, but, I am required to do so.
I have been bit a number of times by the way it handles Ranges, so, I just don't use them and opt instead for the method you used - loop and fill.
If you have other Excel/VBA questions, ask away... I will answer what I can.
Tim
|
|
|
|
|
I am a VB.net student and have had a relatively easy go of it til now. For some reason the concept of threading has been a problem for me. Our assignment is to make a ball bounce around the screen (changing directions when it hits a wall). It must us a class (ball). and I understand the basic code of making the ball change directions, but have no idea on how to incorporate this using threads. Any pointers or starters would be great.
|
|
|
|