|
Use
Dim arrTest() as string = new string(){}
That gets you an array but it's size is not specified.
You also need to ReDim the array - look it up in the online help.
You can just use the ReDim with your existing Dim if you want but whatever you do you're going to have to use it somewhere.
Regards
David R
|
|
|
|
|
Yeah, what I ended up doing was similar
Dim arrTest(1) as string
Then once I know what i is I -
reDim arrTest(i)
Not exactly a bug, but pretty weird if you ask me.
Thanks
|
|
|
|
|
I'm afraid that's the way the language works.
If you think about it your first Dim is just saying I want to use an array, but it does not say how big an array. Nor does it actually create an array - that does not happen until you do a 'new'.
In any case glad you have a solution.
Might be worth looking at Dave K's reply - he's usually very good and in this case his is a better solution.
Regards
David R
|
|
|
|
|
If you don't know the size of the array ahead of time, just use a Generic collection instead, such as:
Dim test As new List(Of String)
test.Add("Some string")
|
|
|
|
|
Thanks, but I really do need an array as I end up putting the array in an array with another array.
I just end up doing this -
Dim testArray(1)
reDim testArray(i)
Thanks
|
|
|
|
|
Dave's...code is still better
Dim test As New List(Of String)
test.Add("Some string")
test.Add("Some other string")
test.Add("and another")
Dim sa() As String = test.ToArray
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
hi, I am Rana
I am using vb.net to accomplish following task:
1) read a csv file from hard disc
2) display it on DataGridView
3) use the datagridview to update an existing access dataset table which has exactly same number of fileds as input csv file displayed in datagridview
4) add query to the updated datset table
5) exporting the result to a text file
So far I cud only hab done until step 2. I desperately need help on rest of 3 steps. Here is my code:
Code Block:
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then
Dim fi As New FileInfo(OpenFileDialog1.FileName)
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Text;Data Source=" & fi.DirectoryName
Dim objConn As New OleDbConnection(sConnectionString)
Dim objDataSet As DataSet = New DataSet()
objConn.Open()
Dim objCmdSelect As New OleDbCommand("SELECT * FROM " & fi.Name, objConn)
Dim objAdapter1 As New OleDbDataAdapter
objAdapter1.SelectCommand = objCmdSelect
objAdapter1.Fill(objDataSet, "test")
DataGridView1.DataSource = objDataSet.Tables(0).DefaultView
objConn.Close()
End If
End Sub
End Class
Please help me on how i can do above three things ASAP.
|
|
|
|
|
Sorry, but this has "homework assignment" written all over it. We're not going to write your code for you. You wouldn't learn anything that way.
Everything you need has already been covered in your class.
|
|
|
|
|
Hello Dave Kreskowiak,
please believe me its not a homework assignment. actually I am doing it as a part of the development. I have been trying :
objAdapter1.Update(Me.Db1DataSet.Sheet1)
but its not working. I just want your help on updating the database with this datgridview that's all. Rest I can do. Please help me!
|
|
|
|
|
rajulama wrote: I just want your help on updating the database
A word of advice, the verb to Want is too abrasive to use when you are the one making a request from a position of weakness. It's better to use the subjective, i.e. "would like". Same principal I know applies in Spanish and German and I would expect to be fairly universal. Put simply it's the polite way to make a request of somebody you have no authority over.
Not that it'll help you here, mind.
Also, for the love of God, use a decent naming system!
10110011001111101010101000001000001101001010001010100000100000101000001000111100010110001011001011
|
|
|
|
|
sorry,
I would be really grateful to you if you could help me. Please don't mind. Help me out, please!
|
|
|
|
|
MidwestLimey was correct and you're still not quite getting it. It's not polite to ask for help and then in the same request demand it with an exclamation mark. So lets practice as if you were going to ask for help from Dave, you could try kissing his a$$ a little like:
"Dave the almighty who rules next to Xerxes - could you find it in your gracious heart to feel pity upon my disgraced soul and help me with my problem? I am nothing without your assistance and bow before your presence."
Or...........you could simply ask for help without it demanding, caps, or !s. Your problem does kind of look like a homework assignment.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Jon_Boy wrote: "Dave the almighty who rules next to Xerxes - could you find it in your gracious heart to feel pity upon my disgraced soul and help me with my problem? I am nothing without your assistance and bow before your presence."
OK, OK, I don't need to be wiping your lipstick off my ass!
|
|
|
|
|
+5 for the wit, -5 for not wanting a little lipstick on the ass.
|
|
|
|
|
If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then
Dim fi As New FileInfo(OpenFileDialog1.FileName)
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Text;Data Source=" & fi.DirectoryName
Dim objConn As New OleDbConnection(sConnectionString)
Dim objDataSet As DataSet = New DataSet()
objConn.Open()
Dim objCmdSelect As New OleDbCommand("SELECT * FROM " & fi.Name, objConn)
Dim objAdapter1 As New OleDbDataAdapter
objAdapter1.SelectCommand = objCmdSelect
objAdapter1.Fill(objDataSet, "test")
DataGridView1.DataSource = objDataSet.Tables(0).DefaultView
objConn.Close()
After this I wrote:
objAdapter1.Update(Me.Db1DataSet.Sheet1("test"))
Because the dataset that I want to update is in by DB1DataSet.Sheet1. I dont want to update the datagridview itself. I want to update an existing database called DB1DataSet.Sheet1 from the datagridview.
when I wrote above line its says following error:
Error 1 Overload resolution failed because no accessible 'Update' can be called with these arguments:
'Public Function Update(dataTable As System.Data.DataTable) As Integer': Value of type 'WindowsApplication1.db1DataSet.Sheet1Row' cannot be converted to 'System.Data.DataTable'.
'Public Function Update(dataRows() As System.Data.DataRow) As Integer': Value of type 'WindowsApplication1.db1DataSet.Sheet1Row' cannot be converted to '1-dimensional array of System.Data.DataRow'.
'Public Overrides Function Update(dataSet As System.Data.DataSet) As Integer': Value of type 'WindowsApplication1.db1DataSet.Sheet1Row' cannot be converted to 'System.Data.DataSet'.
|
|
|
|
|
rajulama wrote: but its not working
If you want help, you have to give more information. What isn't working? What error message are you getting? Show us what code you have so far. We're not going to do your work for you, but if you have a specific problem we can try to point you in the right direction to get help.
|
|
|
|
|
If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then
Dim fi As New FileInfo(OpenFileDialog1.FileName)
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Text;Data Source=" & fi.DirectoryName
Dim objConn As New OleDbConnection(sConnectionString)
Dim objDataSet As DataSet = New DataSet()
objConn.Open()
Dim objCmdSelect As New OleDbCommand("SELECT * FROM " & fi.Name, objConn)
Dim objAdapter1 As New OleDbDataAdapter
objAdapter1.SelectCommand = objCmdSelect
objAdapter1.Fill(objDataSet, "test")
DataGridView1.DataSource = objDataSet.Tables(0).DefaultView
objConn.Close()
End If
I have this and now to replace the data in existing database with that in datagridview I am using:
objAdapter1.Update(Me.dataset.filename)
But its not making any change in dataset table.rest is ok.
|
|
|
|
|
Show us the code around your update statement. Is your command still setup when you issue the update? Shouldn't your update statement be something more like this:
odjAdapter1.Update(Me.objDataSet.Tables("test")) ??
|
|
|
|
|
rajulama wrote: please believe me its not a homework assignment
Ok, I'll take your word
rajulama wrote: actually I am doing it as a part of the development.
If I can not get my work done at my job, then I'll have to face the reality. Shouldn't you?
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
When you right click on the desktop you get a context menu that has something like that:
-----------------------
Arrange Icons By
Refresh
-----------------------
Paste
Paste Shortcut
-----------------------
New
-----------------------
Properties
-----------------------
I need to add a link to my application on Desktop's context menu. How can I accomplish that? What registry key do I need to modify/add to get my app icon listed on the desktop context menu?
E.g.:
---------------------------
Arrange Icons By >
Refresh
---------------------------
My App Link >
Paste
Paste Shortcut
---------------------------
New
---------------------------
Properties
---------------------------
Please help. Thanks.
|
|
|
|
|
Not sure if we got it yet, could you post the question again? (snicker)
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
You posted the exact same question 4 hours ago. Don't. What you're doing is considered very rude and will only get you ignored.
We don't get paid to answer everyones questions. We do this on a volunteer basis, when we can, for as long as we can. Myself, I just woke up 30 minutes ago. Sorry if I wanted to get some breakfast before diving into your question.
|
|
|
|
|
Dave Kreskowiak wrote: I just woke up 30 minutes ago
Good Morning to you.
I don't know why you can't answer questions when you are asleep. I do some of my best work whilst asleep.
|
|
|
|
|
Now if only you could telepathically port your dream code into actual code......
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
All my coding works like a dream
(Well, in my dreams anyway)
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|