|
|
Hey everyone, I'm new to this forum. I'm hoping someone can help me understand how to update a table created in visual studio from an unbound datagrid control in a form. The data in the grid control is populated from a text file I import and want to save to the table. Below is the code I'm using. Any thoughts?
[code]
If IsDBNull(Me.FileData.Text) Or Len(Me.FileData.Text) < 1 Then
MsgBox("You must select the reformatter flate file", MsgBoxStyle.Information)
Exit Sub
Else
Using MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser(Me.FileData.Text)
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
While Not MyReader.EndOfData
FlatFileImportDataGridView.DataSource = Nothing
Try
currentRow = MyReader.ReadFields()
FlatFileImportDataGridView.Rows.Add(currentRow)
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
"is not valid and will be skipped.")
End Try
End While
End Using
'FlatFileImportDataGridView.DataSource = FlatFileImportBindingSource
Dim dr As New System.Windows.Forms.DataGridViewRow
For Each dr In Me.FlatFileImportDataGridView.SelectedRows
'Me.DataGridView2.Rows.Add(dr.Cells(0).Value, dr.Cells(1).Value, dr.Cells(2).Value, dr.Cells(3).Value, dr.Cells(4).Value, dr.Cells(5).Value, dr.Cells(6).Value, dr.Cells(7).Value)
Next
For Each row1 As DataGridViewRow In FlatFileImportDataGridView.Rows
Dim copyrow As DataRow = Me.Database1DataSet.FlatFileImport.NewRow
For Each col As DataGridViewCell In row1.Cells
copyrow(col.Value) = (col.Value)
Next
Me.Database1DataSet.FlatFileImport.Rows.Add(copyrow)
Next
Me.FlatFileImportTableAdapter.Update(Me.Database1DataSet.FlatFileImport)
End If
[/code]
|
|
|
|
|
AnthonyDailyMail wrote: The data in the grid control is populated from a text file I import and want to save to the table. Below is the code I'm using. Any thoughts?
Yup. Import the old-fashioned way (generate insert-commands) or spend quite some time on MSDN reading on how to update using the adapters.
Bastard Programmer from Hell
|
|
|
|
|
Thanks Eddie. Straight to the point. Could you help me a bit more. You mention generating insert-commands. Can you give an example of how I would do this using my example? I'm still trying to make sense of things.
|
|
|
|
|
|
Hey everyone, I'm taking a different approach. Below is the code I'm using to save data from an unbound datagridview to a table using VB. The unbound datagridview control is called "DataGridView1". The bound datagridview control is called "MyImporterDataGridView". This grid is bound to a table called "MyImporter". Everything seems to work. When I click the button it imports a text file into the unbound datagridview control called "DataGridView1 and then the second datagridview control called MyImporterDataGridView which is bound to the table is filled with the data from the unbound grid which suggest to me that the table is being filled with the data. Problem is when I close the form and go to the table to view the data it's empty. What am I doing wrong here?
If IsDBNull(Me.FileData.Text) Or Len(Me.FileData.Text) < 1 Then
MsgBox("You must select the reformatter flate file", MsgBoxStyle.Information)
Exit Sub
Else
Using MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser(Me.FileData.Text)
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
DataGridView1.Rows.Add(currentRow)
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
"is not valid and will be skipped.")
End Try
End While
End Using
'FlatFileImportDataGridView.DataSource = FlatFileImportBindingSource
Dim dr As New System.Windows.Forms.DataGridViewRow
'For Each dr In Me.FlatFileImportDataGridView.SelectedRows
'Me.DataGridView2.Rows.Add(dr.Cells(0).Value, dr.Cells(1).Value, dr.Cells(2).Value, dr.Cells(3).Value, dr.Cells(4).Value, dr.Cells(5).Value, dr.Cells(6).Value, dr.Cells(7).Value)
'Next
Dim workrow As DataRow
Dim i As Integer
For i = 0 To DataGridView1.Rows.Count - 2
workrow = Database1DataSet.Tables("MyImporter").NewRow()
workrow(0) = DataGridView1.Rows(i).Cells(0).Value 'if the table field is a string
workrow(1) = Val(DataGridView1.Rows(i).Cells(1).Value) 'if the table field is a number
'workrow(2) = Val(DataGridView1.Rows(i).Cells(2).Value) 'if the table field is a number
'workrow(3) = Val(DataGridView1.Rows(i).Cells(3).Value) 'if the table field is a number
'workrow(4) = Val(DataGridView1.Rows(i).Cells(4).Value) 'if the table field is a number
Database1DataSet.Tables("MyImporter").Rows.Add(workrow)
Next
TableAdapterManager.UpdateAll(Database1DataSet)
End If
|
|
|
|
|
Hello,
I appreciate a litle help, i'm a newbiie in programing and i'm developing my skills around VBasic 2010.
I'm tryng to develop a chat to work in a network, without server.
The users login to a central database sql, in there i have de records of host and trhu that
-I easely get de Ip,
-in database i can know who is login,
-i can add to database aswell a record of port.
My problem's, without a server, a client need more than 2 port's to connect to for ex. 10 computers (outher clients) or need 20 port's
2 ports to comunicate with any computer?
I appreciate your wise opinion.
best regards,
BGUALTER
|
|
|
|
|
Yep. You talk on one and listen on the other. So, what's the problem?
|
|
|
|
|
Member 8855904 wrote: My problem's, without a server, a client need more than 2 port's to connect to for ex. 10 computers (outher clients) or need 20 port's
2 ports to comunicate with any computer?
Your "problem" is discovering the other computers.
Stop thinking in an always-connected fashion. If you have 20 IP-addresses, then you can connect to them one atta-time, post your message and disconnect again. Call it broadcasting. No, connecting and disconnecting doesn't take much time.
Bastard Programmer from Hell
|
|
|
|
|
Forget central sql database. MS allows only up to 10 clients connected to a server/database for free. If you have more than 10 clients connected you will have to buy a sql server license...other ways it will not work .
If you have all your clients on the same physical locally network you better use udp multicast clients.
You can connect all clients together by one single multicast IP address and one port number (Rx/Tx).
Some years ago i wrote a small udp client test application that can connect up to 255 clients. With this you can send text messages (chat) to one single client or to all connected clients. In a text box the received messages are listed...
Each multicast client gets his individual PC number by using last digits NNN of its own IP Address XXX.XXX.XXX.NNN and the user name will be set by name of the computer.
If you are interested i could help you with the source code .
Regards Markus
|
|
|
|
|
Is this possible to create an event calendar using Visual Basic.net?
hermaine...",)
|
|
|
|
|
Yes. Now do you have a more specific question?
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
Google: how to create an event calender[^]
I think this would be a good place to start
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
Why is it every noob thinks the language choice severely limits the applications you can write with it??
|
|
|
|
|
it's because they don't really understand what a programming language is...
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
|
|
|
|
|
hermaine...",)
|
|
|
|
|
I have a string:
...point_units="meters">...
and I want to extract the word 'meters' (no quotes). How do I remove the quotes?
This is what I **want** to do:
strUnits = Replace(strUnits, "point_units="","")
strUnits = Replace(strUnits, ">"", "")
The extra quote is killing my syntax. Is there a work around?
This is a VBScript that I'm working on but it seems like it should be similar to VB.
|
|
|
|
|
Brad Fackrell wrote: How do I remove the quotes?
Using a regex as the title of your posts suggests? Otherwise, the string.Replace function would indeed do the trick too.
Why not capture the characters between the quotes? Sounds like that's what you're after.
Bastard Programmer from Hell
|
|
|
|
|
Eddy Vluggen wrote: Why not capture the characters between the quotes?
That is exactly what I want to do. In the end I want my string to be meters. I can do this all day long until my string contains a quote. I'm trying to figure out how to deal with quotes when I need to use quotes to group my syntax.
Your right, my choice of words may be confusing. I do the best I can.
|
|
|
|
|
To include a " within a string "" is to be used. Accordingly, if we put "" in the string, the meters can be extracted as shown below
<script type="text/vbscript">
strUnits = "point_units=""meters"">"
strUnits = Replace(strUnits, "point_units=""","")
strUnits = Replace(strUnits, """>", "")
document.write(strUnits)
</script>
|
|
|
|
|
VJ Reddy wrote: "point_units=""","")
Ah...the old extra quote trick. Many thanks!
|
|
|
|
|
You're welcome and thank you for the response.
|
|
|
|
|
I would use RegEx, but this is a dirty way to do it:
Dim strUnitsResolved As String = String.Empty
Dim strUnits As String = "point_units=""'meters'"">"""
strUnits = Replace(strUnits, "point_units=""'", "")
strUnitsResolved = Replace(strUnits, "'"">""", String.Empty)
MsgBox(strUnitsResolved)
|
|
|
|
|
I have one ActiveX DLL which contain a form and class module.
I need to stop the form execution(end the form without displaying it) if some conditions are not satisfying.
but Form1.Hide ,Unload Me and End are not working and throwing Run time Errors
only Exit sub is working but it does not stop form showing.
but my requirement is I have to close the application as soon as the conditions proved wrong.
Please help me .
|
|
|
|
|
Run time errors? You mean exceptions?
Can you paste the exception information here? (Log the exception using Exception.ToString in a try-catch block)
Bastard Programmer from Hell
|
|
|
|