|
Is there something wrong with this line ...
Dim totValue As Integer = CInt(tblDataTable.Compute("SUM(Value)", "Product = 'P199'"))
It doesn't seem to do anything. I put totValue into a messagebox immediately after it, but it simply ignores it and carries on - infact a Try ... Catch in the same area is invoked unnecessarily.
So, I tried removing the 'filter' part of compute (I'm still new to this, and I believe that its optional), so that I had:
Dim totValue As Integer = CInt(tblDataTable.Compute("SUM(Value)"))
But this just underlines the tblDataTable.Compute("SUM(Value)") part in my code, with the 'tooltip', "Argument not specified for parameter 'filter' of 'Public function compute'.
What am I doing wrong?
|
|
|
|
|
penguin5000 wrote: CInt
You should not use this, it's VB6 nastiness. Use Convert.ToInt32 instead, or int.Parse.
The MSDN samples put Sum, not SUM. I wonder if it's case sensitive ?
I'd break it into steps, so you can see which one fails.
Christian Graus - C++ MVP
|
|
|
|
|
Unfortunately, it still isn't working. Is it the way I'm constructing my DataTable? The relevant section is as follows. I'd really appreciate some pointers:
Dim myStreamReader As StreamReader = New StreamReader(txtFilePath.Text)<br />
Dim strLine As String<br />
Dim strProdCode As String<br />
Dim strTransCode As String<br />
Dim intQuantity As Integer<br />
Dim intValue As Integer<br />
Dim intRunningQuantityTotal, intRunningValueTotal As Integer<br />
Dim intNumberOfRows As Integer<br />
Dim tblDataTable As New DataTable<br />
<br />
tblDataTable = New DataTable("TrxContents")<br />
<br />
Dim colProds As DataColumn = New DataColumn("Product")<br />
Dim colTrans As DataColumn = New DataColumn("Trans Code")<br />
Dim colQty As DataColumn = New DataColumn("Quantity")<br />
Dim colValue As DataColumn = New DataColumn("Value")<br />
Dim row As DataRow<br />
<br />
tblDataTable.Columns.Add(colProds)<br />
tblDataTable.Columns.Add(colTrans)<br />
tblDataTable.Columns.Add(colQty)<br />
tblDataTable.Columns.Add(colValue)<br />
<br />
intRunningQuantityTotal = 0<br />
intRunningValueTotal = 0<br />
intNumberOfRows = 0<br />
intOriginalLines = 0<br />
<br />
Try<br />
<br />
Do While myStreamReader.Peek <> -1<br />
strLine = myStreamReader.ReadLine()<br />
intOriginalLines = intOriginalLines + 1<br />
<br />
If strLine.Substring(0, 1) = "K" Then<br />
row = tblDataTable.NewRow()<br />
intNumberOfRows = intNumberOfRows + 1<br />
<br />
'Read the Product Code (start at pos 6. 26 chars long)<br />
strProdCode = strLine.Substring(5, 26)<br />
row.Item("Product") = strProdCode<br />
<br />
'Read the transaction code (start at pos 63. 2 chars long)<br />
strTransCode = strLine.Substring(62, 2)<br />
row.Item("Trans Code") = strTransCode<br />
<br />
'Read the Quantity (start at pos 74. 12 chars long)<br />
intQuantity = strLine.Substring(73, 12)<br />
row.Item("Quantity") = intQuantity<br />
intRunningQuantityTotal = intRunningQuantityTotal + intQuantity<br />
<br />
'Read the Value (start at pos 86. 14 chars long)<br />
intValue = strLine.Substring(85, 14)<br />
row.Item("Value") = intValue<br />
intRunningValueTotal = intRunningValueTotal + intValue<br />
<br />
tblDataTable.Rows.Add(row)<br />
<br />
End If<br />
<br />
Loop<br />
myStreamReader.Close()<br />
<br />
Dim ds As New DataSet<br />
ds = New DataSet<br />
<br />
Dim totValue As Integer = Convert.ToInt32(tblDataTable.Compute("Sum(Value)", "Product = 'P199'"))<br />
MessageBox.Show(totValue)<br />
<br />
ds.Tables.Add(tblDataTable)<br />
Me.grdDataGrid.SetDataBinding(ds, "TrxContents")<br />
<br />
Catch<br />
<br />
... some stuff<br />
<br />
End Try
Thanks in advance.
|
|
|
|
|
Best guess, looking at this code, Value is not a numeric type, which means that Sum won't work on it.
Christian Graus - C++ MVP
|
|
|
|
|
Thanks.
A couple of minor changes:
Dim colValue As DataColumn = New DataColumn("Value", GetType(Integer))<br />
<br />
intValue = Integer.Parse(strLine.Substring(85, 14))
|
|
|
|
|
*grin* Glad to help.
Christian Graus - C++ MVP
|
|
|
|
|
Can you write me why is vb.net batter then oracle? I just want to know...
|
|
|
|
|
u're sentece is out of mind.. we don't understand u. u compares an apple with a car.. oracle is a company and vb.net is a programming language
|
|
|
|
|
I have a problem for datagrid. For now i am able to display wat i wan on the datagrid but the users are able to edit the data on the datagrid and in turn corrupt my DB. What can i do to allow the user to read only but not to write?? Urgent... thanks a lot....
|
|
|
|
|
Subjugate wrote: What can i do to allow the user to read only but not to write??
datagrid1.ReadOnly = true
When you get mad...THINK twice that the only advice
Tamimi - Code
|
|
|
|
|
Where should i enter tis line. In the datagrid or in the button? Cos in order to activate my datagrid i need to click on a button 1st.
|
|
|
|
|
at the design time set the readonly property to true.
When you get mad...THINK twice that the only advice
Tamimi - Code
|
|
|
|
|
okok.. Thanks a lot..
|
|
|
|
|
Just enter it anywhere in the code before you actually show the datagrid to the user.
Alternatively you can use this function, that will also lock you dataset for added protection. Just call it before you show your datagrid to the user.
<br />
Private Function ColumnLock(ByVal key As Boolean)<br />
Try<br />
Dim col As DataColumn<br />
YourDataGrid.DataSource = YourDataSet<br />
YourDataGridPA.SetDataBinding(YourDataSet, "YourTableName")<br />
YourDataGrid.ReadOnly = key<br />
For Each col In YourDataSet.Tables(0).Columns<br />
col.ReadOnly = key<br />
Next col<br />
Catch Ex As Exception<br />
msgbox(Ex.message)<br />
End Try<br />
End Function<br />
Johan
|
|
|
|
|
I'm looking for a comprehensive list of properties and methods for the Windows Media player control so I can control it programmatically rather than letting the user muck with the controls. So far all I can find is methods and properties for older versions. I'm gonna keep searching Google, but if anyone knows any lists off hand, let me know.
Thanks.
PS. I'm using VB 6
"Go to, I’ll no more on’t; it hath made me mad." - Hamlet
|
|
|
|
|
|
Hi
I had a strange problem. I had incoroporated ActiveX webbrowser control in windows forms (using vs.net 2003). I had recorded some events like click occured on the browser and stored them in the datatable as rows(one row for each event). Now what i want to do is run all these rows one by one. My problem is that the documentcomplete as well as navigatecomplete2 events doesnt fire until the whole method written for the running the events is executed. It creates a problem like i am not able to get the refreshed page in document object after navigation to a new page. Any help will be appriciable.
Thanks & Regards
Gurmeet Singh
|
|
|
|
|
Does anyone help me on network programming with vb.net?
I started new project on database programming over the network.
My project is desktop base application (not web base application), I don't know your country call that desktop application but my country (Thailand) does.
I search on the internet and I found that I must use socket.
I understand the database programming but network I can't.
I try to apply the sample code from internet with my project but it's all fail.
I have tried this about 1 month.
If anyone can solve on this topic, please help me.
My project is manipulate data on client that follow this strp
1. Client send the request to server.
2. Server will query data from main database then generate a xml file and send it to client.
3. Client recieve the text file and update the local database.
4. Client manipulate data.
5. Client query updated data and generate a xml file then send it to server.
6. Server recieve the text file and update main database.
I don't connect the main database via notwork for security. I can check text file format and block it anyway.
P.S.
I'm a Thai student and my English language skill so weak, please try to understand my words.
Thank you very much.
Sitt
|
|
|
|
|
Hi Sitt,
We have a setup in our company that sounds similar to what you describe. We have a very simple approach that works very nicely.
Our client application contains code to create xml files, and other code that can read xml files. Same thing for the server application.
When the server app does something that should influence whatever happens on the client machines, it creates an xml file with the necessary data, and copies it to a shared or ftp folder.
The client app checks this folder on a regular basis, and when it finds an xml file it reads it, and does something with the data. When the client app does something that should influence the server, it creates an xml file of its own and puts it in the same (or another) shared folder. The server also checks the folder on a regular basis, etc.
This process is very easy to secure, and to create, but it is not very good if you need to have very fast traffic between clients and server.
Hope this helps you,
Johan
|
|
|
|
|
Dim dtrReader As SqlDataReader = cmdCommand.ExecuteReader()
Try
While dtrReader.Read()
lstViewBuyers.Items.Add(dtrReader(1))
End While
Finally
dtrReader.Close()
End Try
this is how i display one field from the database to the listview... but my problem is when i come to display one row/record from the database to the listview...
How can i display the whole record in the sql database to using listview control?
pls help
nothing is impossible.....
|
|
|
|
|
By using a string builder to build a string out of the data in the row, and then adding that.
(1) is returning the second column, you can access them by name or index ( name is more self documenting ), you can build the string any way you like. There's no way to make the string build itself.
Christian Graus - C++ MVP
|
|
|
|
|
one way but not a good way is concatinate all of your field together that the query result is become to 1 field e.g.
sql --> "select f1 + ' ' + f2 + ' ' + f3 + ' ' + f4 from TableName"
' ' is white space, f1 to f4 is field name
result --> "aaa aaa aaa aaa"
"bbb bbb bbb bbb"
"cccc ccc cc ccccc"
the output format is not order in column but it's ok if the data is name and surname
|
|
|
|
|
Hi,
I have solved this problem simply as follows:
lstViewBuyers.Items.Add(dtrReader(1) & "|" & dtrReader(2))
I.e. you just concatenate all the fields from the record into a string with a divider between the values.
Afterward, if you want to use any part of the record, selected from the listview, you just itirate through the string. The | character (ofcourse you can use any other character or string) serves as the divider. Something like this:
Dim divider As String = "|"<br />
Dim cut As Integer<br />
Dim TheBitYouNeed As String<br />
cut = TheBitYouNeed.IndexOf(divider)<br />
TheBitYouNeed= Mid(TheBitYouNeed, 1, cut)
Hope this helps you,
Johan
|
|
|
|
|
Hey, another way of doing this if you don't know the amount of columns in the table you are getting would be:
<br />
Try<br />
While dtrReader.Read()<br />
Dim lvItem As New ListViewItem(dtrReader(0))<br />
For i As Integer = 1 To dtrReader.FieldCount - 1<br />
lvItem.SubItems.Add(dtrReader(i))<br />
Next<br />
lstViewBuyers.Items.Add(lvItem)<br />
End While<br />
<br />
Finally<br />
dtrReader.Close()<br />
End Try<br />
Bsically the same thing, but since the data reader has field information on it, we just use that and create the sub items from the datareader starting at the 1 position. Have you thought of using a bindable list view?
You may want to check to see if nulls are coming back though, you may get exceptions when you get data from a datareader that has null values and try to add it to a list view item like this.
|
|
|
|
|
Excel can load a CSV. A CSV is just a file, it can't do ANYTHING, except represent data. If you open a .CSV file in Excel, it will open with each comma being a column.
Christian Graus - C++ MVP
|
|
|
|