ddanbe commented: Nice! +14
Begginnerdev commented: Nice work, friend! +9
This is the structure of a CSV File yours loads into a datagrid but the info is all lumped together
EXTENSION,DESCRIPTION,EXECUTABLE_PATH
.001,None,C:\Program Files\7-Zip\7z.exe
.323,H.323 Internet Telephony,rundll32.exe
.386,Virtual device driver,NO DEFAULT PROGRAM SET
.3g2,3GPP2 Movie,C:\Program Files\QuickTime\QuickTimePlayer.exe
.3gp,3GPP Movie,C:\Program Files\QuickTime\QuickTimePlayer.exe
.3gp2,3GPP2 Movie,C:\Program Files\QuickTime\QuickTimePlayer.exe
.3gpp,3GPP Movie,C:\Program Files\QuickTime\QuickTimePlayer.exe
.669,Composer 669 Module,NO DEFAULT PROGRAM SET
.7z,None,C:\Program Files\7-Zip\7z.exe
.aa,None,NO DEFAULT PROGRAM SET
.aac,None,C:\Program Files\QuickTime\QuickTimePlayer.exe
.aax,None,NO DEFAULT PROGRAM SET
Anyway try the following code after you load the datatable
For i As Integer = 0 To 9
ds.Tables(0).Rows(i).Delete()
Next
ds.Tables(0).AcceptChanges()
It should remove all the rows above the START row.
Please post some of your CSV file. We do n ot know what your column names are or what your data looks like.
As for your wanting rows 98 - 156 use the following.
cnt is an integer variable: cnt = objDataset.Tables(0).Rows.Count - 1
For i As Integer = cnt To 0 Step -1
If i < 98 Or i > 156 Then
objDataset1.Tables(0).Rows(i).Delete()
End If
Next
ds.Tables(0).AcceptChanges()
I would like to see a sample of your csv file the first 3 rows should be enough.
Where line of code caused "No value given for one or more required parameters. i got this error sir" error?
Does your DataAdapter have an Update Command Query Set? Also removeBindingSource1.ResetBindings(False)
Does your ACCESS table have a Primary Key?
Ok the Select Case was a demo so you could create your queries by which checkbox was checked. You really need to study up on your ADO.Net. I'm not trying to be condescending but the questions your asking tell me you need to do a little research on SQL Server operations with VB.Net. Click Here
You create a command, connection, dataadapter, and datatable or dataset. Then you use the data in the datatable to populate your controls. For the Listbox you need the following query "Select Last_First_Name From [tablename];" that's your Command's Text. You would populate the ListBox using a SqlDataReader
Click Here
If your CSV File has headers you can Just get the columns you want by the SELECT Query.
Dim objCmdSelect As New OleDbCommand("SELECT Col1,Col2,col3... FROM " & fi.Name, objConn)
Your query for the selected person from the ListBox should be like
SELECT Field1, Field2, Field3... FROM [TableName] WHERE Last_First_Name = 'selectedName';
Use the following to create your queries based on the CheckBoxes Checked State
Select Case True
Case CheckBox1.Checked And CheckBox2.Checked
MsgBox("Both CheckBoxes Are Checked")
Case CheckBox1.Checked
MsgBox("CheckBox 1 Checked")
Case CheckBox2.Checked
MsgBox("CheckBox 2 Checked")
Case Else
MsgBox("No Checkbox Is Checked")
End Select
I haven't had a chance to test this but I'm pretty sure you can ->Instead of deleting your record from the datatable. Me.TransmissoesDataSet.Tables("utilizador_Avancado").Rows(itemFound).Delete()
Remove the item from the BindingSource and call ResetBindings(False) Method.
bs.RemoveAt(itemFound)
bs.ResetBindings(False)
Then Accept changes method on the table. You should be able to use the Adapter Update then.
Very True Minimalist I just tested my code and it didn't matter they just have to be distinct
Yes I understand that it returns the matching elements. I went to the MSDN and read that it only returns Distinct elements that match so that is probably why the one l is all I got back. Also, I didn't realize they had to be in the same position(index) of the collection.
I guess I will have to find some other method to get all the matching elements whether or not they're Distinct. I was hoping that was my answer as it's not a lot of coding but what would be the fun!!!!
You will need to decide which fields you'll be needing from your sql server datatable. then you can create the commands, connection, dataadapter, and dataset.Then you can use the field with the names for your ListBox.
Here is a MSN page on how to fill your dataset.
Click Here
SQL Server Connection Strings Click Here
Once you get that going, let me know, then we can move on to the selecting records by the selected name.
I have a question about the string.intersect method.
I am not getting the results I expect.
Dim lstChars1() As Char = "hello dolly" 'TextBox1.Text.ToCharArray
Dim lstchars2() As Char = "help melanie" 'TextBox2.Text.ToCharArray
Dim lst1 As New List(Of String)
Dim lst2 As New List(Of String)
For Each c In lstChars1
lst1.Add(c.ToString)
Next
For Each c In lstchars2
lst2.Add(c)
Next
Dim lstNew As IEnumerable(Of String) = Nothing
lstNew = lst1.Intersect(lst2, StringComparer.OrdinalIgnoreCase)
lstNew contains "h", "e", "l", " "
I expected another 'l", What's the reason for this behavior? I have also attempted this using arrays and received the same values.
Thanks In Advance
What exactly are you trying to do? You have an array of Button then you give a variable btnName a type Button without using it. Then you take your button in the array and try to create a new button without the array index. Not sure what event handler you are using either I suppose it's the click events for both buttons you have in the array.
Anyway I believe your problem is the array is not being loaded when the form is opened. i ran your code and added the buttons to the array in the load event. Not sure why your looping thru the array and setting the value of toothName it will always be your second button name
Dim btns(1) As Button
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
btns(0) = Me.Button1
btns(1) = Me.Button2
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button1.Click, Button2.Click
'Dim btnName As Button = DirectCast(sender, Button)
Dim i As Integer
'btns(i) = New Button
Dim toothName As String = ""
Try
For i = 0 To btns.Length - 1
toothName = " " & btns(i).Text & " - Upper " '<- in here it says Object reference not set to an instance of an object
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
That will stop your Object Reference Not Set Error and maybe you can go on from there
I was a little too hasty with my previous post it should have been:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim lstChars1() As Char = TextBox1.Text.ToCharArray
Dim lstchars2() As Char = TextBox2.Text.ToCharArray
Dim ch As IEnumerable(Of Char) = lstChars1.Intersect(lstchars2)
Dim out As String = String.Join(",", ch)
MsgBox("There are " & ch.Count & " matching characters" & vbCrLf & out)
End Sub
I would load the listbox with the names and when the user clicks the name you could execute a query against either the database or a DataSet to get your data about the person.
I'm not much into the binding of controls because mine usually fail when I need to do some workarounds which inevitably happens. So I all my coding of database to controls by hand. I've always hated the way Visual Studio stores the connectionString and all the DataSource operations. That's only my opinion and I know a lot of coders on here and elsewhere will frown on that but that's just me.
Anyway You could use LINQ against your datatable to retrieve the data you want about the selected person and display it in Textboxes or in Lables or even in a multiline textbox using some formating.
ignnniter, see if this helps you get your head around it.
I have a button and two textboxes on a form use the default names in the click event put this.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim lstChars1() As Char = TextBox1.Text.ToCharArray
Dim lstchars2() As Char = TextBox2.Text.ToCharArray
Dim ch As IEnumerable(Of Char) = lstChars1.Intersect(lstchars2)
Dim sb As New System.Text.StringBuilder
For Each c In ch
sb.Append(c & ", ")
Next
sb.Remove(sb.Length - 2, 2)
MsgBox("There are " & ch.Count & " matching characters" & vbCrLf & sb.ToString)
End Sub
First what are the 2 datasources? it looked from your first images of the data it was all in one table: Second what is supposed to happen when you click on a name in your listbox?
Start4me;
Sorry for the delay in replying...
I would have either have a textbox for each type of phone or some checkboxes or radiobuttons to determine which phone you'd want to query.
Probably shouldn't help dredge up this post but it was never actually answered in VB so here goes. Intellisense will give you 10 choices of how you want to Align your header text. VS2008 / 2012
DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter
The following code shows how to put a table and some other minor things into a word doc. It's part of a database schema app. displaying the table name column names and their datatype ordinal position and if nullable. So the dbname and the table name are not important just strings. the datatable has to have data with column names. You will also need a reference to Microsoft.Office.Interop.Word
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Word
Public Class WordDoc
''' <summary>
''' dTbl - The table you wish to display
''' tblName - Name of the Table
''' dbName - the database File Path and Name
''' </summary>
''' <param name="dTbl"></param>
''' <param name="tblName"></param>
''' <param name="dbName"></param>
''' <remarks></remarks>
Public Sub New(ByVal dTbl As DataTable, ByVal tblName As String, ByVal dbName As String)
Dim oApp As Word.Application
Dim oDoc As Word.Document
Dim oPara1 As Word.Paragraph
Try
'Start a new document in Word
oApp = CType(CreateObject("Word.Application"), Word.Application)
oDoc = oApp.Documents.Add()
Dim rws As Integer = dTbl.Rows.Count
Dim cols As Integer = dTbl.Columns.Count
' Clear out any existing information.
oDoc.Range.Delete()
oPara1 = oDoc.Content.Paragraphs.Add
oPara1.Range.MoveStart()
oPara1.Range.Text = tblName & " TABLE"
oPara1.Range.Font.Size = 10
oPara1.Range.Font.Bold = CInt(True)
oPara1.Format.SpaceAfter = 4
oPara1.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
oPara1.Range.InsertParagraphAfter()
Dim tlb As Word.Table
tlb = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, CInt(rws + 1), CInt(cols))
oApp.Visible = True
tlb.Style = "Table Grid 8" '"wdTableFormatGrid8" '"Table Grid 7" "Table Columns 5"
'Data Rows
For j As Integer = 0 To CInt(rws) 'no -1 here as the headers need to be added
If j = 0 Then
For …
If your problem is solved you should mark it as such.
Can you show some code where your error is happening. From the message it would seem you are trying to execute a query with the connection Closed.
Why not bind the datagridview to a bindingsource. the reset the bindingsource.
You will need a datatable or a collection but that should give you what you want. All you have to do is clear the datasource of the bindingsource and call the ResetBindings(False) method on the bindingsource
Quick and dirty demo
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim filePathAndName As String = SelectFile()
If filePathAndName IsNot Nothing Then
Dim dir As String = GetFolder()
If dir IsNot Nothing Then
My.Computer.FileSystem.CopyFile(filePathAndName, dir & "\" & _
System.IO.Path.GetFileName(filePathAndName), True)
End If
End If
End Sub
Private Function GetFolder() As String
Dim fldr As String = Nothing
With fbd1
.Description = "SELECT DIRECTORY FOR EXCEL FILE"
.ShowNewFolderButton = True
Dim dlgResult As DialogResult = .ShowDialog()
If dlgResult = Windows.Forms.DialogResult.OK Then
fldr = .SelectedPath
Else
MsgBox("EXCEL FILE WASN'T SAVED")
fldr = Nothing
Return fldr
Exit Function
End If
End With
Return fldr
End Function
Private Function SelectFile() As String
Dim file As String = Nothing
With ofd1
.InitialDirectory = "c:\"
.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
.Multiselect = False
.RestoreDirectory = True
If .ShowDialog = DialogResult.OK Then
file = .FileName
End If
End With
Return file
End Function
End Class
You didn't provide the name for the file in the destination
My.Computer.FileSystem.CopyFile("C:\Users\coder\Desktop\EXCEL PROJECT\excel\1_2012.xlsx", My.Computer.FileSystem.SpecialDirectories.Desktop & "\TestCopy.xlsx", True)
Try the following in your code. If it doesn't work take the single quotes from around searchStr it is probably Type integer in the Database Table
Dim cmd As New OleDbCommand
Dim da As OleDbDataAdapter
With cmd
.CommandText = "select * from car where Renter_ID = '" & searchStr & "'"
.CommandType = CommandType.Text
.Connection = conn
End With
da = New OleDbDataAdapter()
With da
.SelectCommand = cmd
.Fill(dt)
.Dispose()
End With
Hello Jimmy_1,
Just want to ask a few questions. From each of the worksheets how many Columns are you totaling and Are you Creating a new Worksheet in a new workbook from the others or do you just need the totals of the columns?
For the Daily run you could set a Scheduled Task of your VB.net project executable so that's not a problem.
Thank You all for your quality responses. I really appreciate the input.
I see from the varying code samples this objective can be skinned in a lot of different way. Again Thank You All!!
I've been working on a Textbox that only accepts 0-9, Decimal Point, and the Backspace Keys. Also keeps it in the base form 0.00. Max value is 999999.99 can be set as needed. It works as expected, but I have to ask if I have remade the wheel. This sub is set as the KeyPress Event for the textboxes on the form and will not allow wrong KeyChar's to be entered. Any tips or criticisms welcome..
''' <summary>
''' Previews the Key stroke attempting to be entered into textbox
''' allows or disallows the key depending on the
''' e.KeyChar, position, and Caret Position.
''' Only 0-9 a single decimal point and 2 places after the decimal.
''' The Backspace key is also allowed
''' Max Value = 999999.99
''' </summary>
''' <param name="sender">TextBox</param>
''' <param name="e"> Handled = true disallows Key :: Handled = False Allows Key
''' </param>
''' <remarks></remarks>
Public Sub BoxKeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
'allow Backspace and exit the sub no need to process further
If e.KeyChar = Chr(8) Then e.Handled = False : Exit Sub
Dim tb As TextBox = DirectCast(sender, TextBox) 'Get the TextBox.
'Fill Physical variables
'Decimal Point(if present) Location :: If not present (-1)
Dim point As Integer = tb.Text.IndexOf(".")
Dim caretIndex As Integer = tb.SelectionStart 'Caret position
Dim len As Integer = tb.Text.Length 'Length of text present already in textbox
'Check if a digit has been entered
If Not Char.IsDigit(e.KeyChar) Then e.Handled = True
'If …
You could use a BindingSource with the DataGridView. Then when your records are inserted successfully call the ResetBindings() Method. Click Here
Add the item to the Combox Items List.
See if the following will help
Dim lstTextboxes As New List(Of TextBox)
Private Sub LoadTextBoxList()
lstTextboxes.Add(txtCustomername)
lstTextboxes.Add(txtPartcode)
lstTextboxes.Add(txtinvo)
End Sub
Private Sub btnTEST_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTEST.Click
Dim query = From tb In lstTextboxes _
Where tb.Text = "" _
Select tb.Name
'CALL SQL METHOD FROM SELECT CASE
Select Case query.First
Case txtCustomername.Name
MsgBox(txtCustomername.Name & " I'm Empty")
Case txtinvo.Name
MsgBox(txtinvo.Name & " I'm Empty")
Case txtPartcode.Name
MsgBox(txtPartcode.Name & " I'm Empty")
End Select
Stop
End Sub
tatacco; "My advice to you is to start drinking heavily" -John 'Bluto' Blutarsky
Im not sure about using the "AND"'s in your UPDATE statement there should be commas seperaing your fields and values. Here is a test query(StoredProcedure) I have in one of my access DB's. If you are going to be using this UPDATE query often you should create a stored procedure and add the parameters to the command in the order they appear in the stored procedure or the sql statements you write in vbCode.
ACCESS Stored Procedure Name = updateSong >>>
"UPDATE SONGS SET SONGS.TITLE = [?], SONGS.LOCATION = [?], SONGS.[SIZE] = [?]
WHERE (((SONGS.ID)=[?]));"
<<<<
VB Code
title, location, size, and id are variables that are set by code
Dim cmdUpdateSong As New OleDb.OleDbCommand()
With cmdUpdateSong
.CommandText = "updateSong"
.CommandType = CommandType.StoredProcedure
.Connection = conn
.Parameters.AddWithValue("@title", title)
.Parameters.AddWithValue("@location", location)
.Parameters.AddWithValue("@size", size)
.Parameters.AddWithValue("@id", id)
End With
Also as Reverend Jim said you need to make sure you have an open and available Connection
I believe you need to set the combobox properties in the proper order.
.DisplayMember = "Need to set this one too"
.ValueMember = "ItemName"
.DataSource = ds.Tables(0)
Also how are you accessing the selecdt item/value when a combobox item is selected? the variables datatype needs to be the same as the valuemember's datatype.
I see in 3 subs you are creating the same named dataset--> DtSet
. The DataSet needs to be Global enough for the consumers of it within the project. This is probably why you are getting the * object reference not set to an instance of an object* error.
For starters
In your Select Query you will need to add a Parameter for @Course.
cmd.Connection = conn
cmd.CommandType = CommandType.Text
cmd.CommandText = sSQL
cmd.Parameters.AddWithValue("@Course",value of Course)
I also wouldn't open the connection until you have the Command Initialized but thats just me.
You could query the worksheet to a datatable. Then loop thru the rows getting the items you want into the ComboBox. After that its just a matter of using the index of the ComboBox Item to get the value for your TextBox. dt.Rows(comboIndex).Item(columnNumber of value you want).ToString.
myconnection = New OleDbConnection("provider=microsoft.ACE.OLEDB.12.0;data source=C:\Users\DELL\Documents\Visual Studio 2012\Projects\WindowsApplication9\WindowsApplication9\NIBM.accdb")
myAdapter = New OleDbDataAdapter("select*from Driverdetails", myconnection)
myAdapter.Fill(Ds, "Driverdetails")
myconnection.Close()
** DataGridView1.DataSource = Ds.Tables(tableName or index)**
DataGridView1.DataMember = "Driverdetails"
End Sub
You need to Set the DataSource of the DataGridView to a particular table of the dataset
If your question has been answered satisfactorily please mark the thread as solved.
Try the following
Dim id as Integer = Command.ExecuteScalar()
In your Sub newGame() You are Dim(ing) a variable named randomNumber instead of just reassigning your global variable new value. Since it's scope is local to only the Sub newGame it will have no effect on the global variable randomNumber and it will be whatever you assigned it in the beginning.
TextBox1.Text = Cstr(Value from the Query)
I did a search on MSDN and Google and couldn't find one entry for the " exchange text box control"... must be something new coming in VS.Net 2014?