|
create a context menu and assign it to listbox.contextmenu
|
|
|
|
|
Hi
I'm trying to use a dataview rowfilter to get the Max, Min, and Ave Order Values for a particular PartNo. (I cannot change the base SQL query, since depending on user input, I need to loop though anything from 10 to 1000 rows, and for each row, get the min, max and average - Too many queries over a network??). For this reason, I pull the whole table via SQL, and am trying to use rowfilters to get the desired values for each row
Dataview.RowFilter = "PartNo = '123' AND Ave(Cost)" gives an error similar to this: Cannot perform AND operation on Boolean and Double. I assume the Boolean part is 'PartNo = '123' and the Double would be the Average Cost returned which does make sense.
Any ideas how I could do this??
Basically I want to implement the following SQL using a rowfilter:
SELECT Ave(Cost) FROM PurchaseOrders WHERE PartNo = '123'
Thanks in advance!!
-- modified at 6:01 Thursday 23rd February, 2006
|
|
|
|
|
Hi,
Dim dtItemCost As New DataTable("Cost")<br />
<br />
dtItemCost.Columns.Add(New DataColumn("PartNo", GetType(String)))<br />
dtItemCost.Columns.Add(New DataColumn("Cost", GetType(Double)))<br />
<br />
Dim drNewItemCost As DataRow<br />
<br />
drNewItemCost = dtItemCost.NewRow<br />
drNewItemCost.Item("PartNo") = "123"<br />
drNewItemCost.Item("Cost") = 10<br />
dtItemCost.Rows.Add(drNewItemCost)<br />
<br />
drNewItemCost = dtItemCost.NewRow<br />
drNewItemCost.Item("PartNo") = "100"<br />
drNewItemCost.Item("Cost") = 100<br />
dtItemCost.Rows.Add(drNewItemCost)<br />
<br />
drNewItemCost = dtItemCost.NewRow<br />
drNewItemCost.Item("PartNo") = "123"<br />
drNewItemCost.Item("Cost") = 30<br />
dtItemCost.Rows.Add(drNewItemCost)<br />
<br />
drNewItemCost = dtItemCost.NewRow<br />
drNewItemCost.Item("PartNo") = "100"<br />
drNewItemCost.Item("Cost") = 105<br />
dtItemCost.Rows.Add(drNewItemCost)<br />
<br />
Dim dblAvgCost As Double<br />
<br />
dblAvgCost = dtItemCost.Compute("Avg(Cost)", " PartNo = '123'")
I hope this will help u...:->
Regards,
Ritesh
|
|
|
|
|
Thank you so much Ritesh
Saved me a lot of time!!
Ritesh1234 wrote: Dim dblAvgCost As Double
dblAvgCost = dtItemCost.Compute("Avg(Cost)", " PartNo = '123'")
I did have to first check that there is actually at least one Item specified by the filter otherwise it throws an exception. (I assume if there are no rows, the Average function would be dividing by Zero - hence an error)
Thanks again - really helpfull
Cheers
Richard
|
|
|
|
|
Hello all,
This is my project: I've made a TreeView that displays a folder and all sub folders within it. I also have an AfterSelect sub (Shown below) that looks through the selected directory and displays any files in a ListView. All this works.
This is my problem: Although I have an imagelist that is connected to the ListView control, it doesn't show the pictures beside the items when they are listed. All I have is a blank space where the picture should be. And when I try to assign an image to an item through the designer it just ignors them. Probably cause everything I'm doing is through the code view not the designer view. The only thing I can think of is that I'm forgetting to code something to tell the listview to show the images. Can anyone help me out?
This is the only code I've written that touches the listview so far.
Private Sub tvwExplorer_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwExplorer.AfterSelect<br />
'Get reference to the selected node<br />
Dim dirInfo As DirectoryInfo = New DirectoryInfo(e.Node.FullPath)<br />
'Clear all the items in the listview<br />
lvwExplorer.Items.Clear()<br />
'Check if the Directory exist or not<br />
If (dirInfo.Exists) Then<br />
'Get reference to all the files<br />
Dim fileInfos As FileInfo() = dirInfo.GetFiles()<br />
'Add all the files to the ListView<br />
Dim info As FileInfo<br />
For Each info In fileInfos<br />
Dim item As ListViewItem = New ListViewItem<br />
item = lvwExplorer.Items.Add(info.Name)<br />
item.SubItems.Add(info.LastAccessTime.ToString())<br />
Next<br />
End If<br />
End Sub
|
|
|
|
|
Darshon wrote: Dim item As ListViewItem = New ListViewItem
item = lvwExplorer.Items.Add(info.Name)
This adds a listview item which does not have an image index. You need to build your list view item so that it contains an image index.
Darshon wrote: Dim item As ListViewItem = New ListViewItem
item = lvwExplorer.Items.Add(info.Name)
This makes no sense. You create a new one, then you throw it away to be replaced by the one returned by Add.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thank you Christian Graus for your comments. I'm fairly new at programing with VB could you give me an example of how you would fix this?
|
|
|
|
|
Nevermind! I got it to work. I downloaded an example project from this site and looked at how s/he assigned an imagelist to an listviewitem and I got it to work on mine. Thanks for your help.
|
|
|
|
|
No worries - I just got in and online, but I'm glad you found a solution
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Object reference not set to an instance of an object.
Dim MyConn As New SqlConnection(ConfigurationManager.ConnectionStrings("psmConnectionString").ConnectionString)
how to solve it?
|
|
|
|
|
Well, at a guess you need to add psmConnectionString to your config file.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
i did put it on the config file.this is the line:
appSettings
add key="psmConnectionString" value="Provider=.NET Framework Data Provider for SQL Server:Data Source=HAPPYFAM-B614E1\SQLEXPRESS;Initial Catalog=psm;Integrated Security=True" appSettings
is it rite?
-- modified at 2:49 Thursday 23rd February, 2006
|
|
|
|
|
>>Dim MyConn As New SqlConnection(ConfigurationManager.ConnectionStrings("psmConnectionString").ConnectionString)
What makes you think that the psmConnectionString item in the config manager will have a connection string property ? Why is it in the ConnectionStrings collection ? I didn't know there was such a thing, but assuming that there is, I'd assume that you need to do something specific to get your config item to appear there.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
You have put the value in the appSettings section and try to access it in the connectionStrings section. Either move it to the connectionstrings, or access it using the AppSettings collection.
---
b { font-weight: normal; }
|
|
|
|
|
when i used the conMyData = New SqlConnection(ConfigurationManager.AppSettings("psmConnectionString")) it has an error.the error is The ConnectionString property has not been initialized. the program stop at Myconn.open().
anything can i do??
|
|
|
|
|
You have a colon instead of a semicolon between the two first properties in the connection string.
---
b { font-weight: normal; }
|
|
|
|
|
Dear All,,
Can U Help me to Generate the XML document from Excel Worksheet by Using Macro and VBA facility...Excel 2003 professional Edition have an option like XML in Data Menu..I have Excel 2003 Standard Edition...
Please Help me to get the Solution
Thanks n Regards,
Ramya.R
|
|
|
|
|
Sub SaveAsXML()
ActiveWorkbook.SaveAs Filename:= "C:\Book3.xml", FileFormat:= _
xlXMLSpreadsheet, ReadOnlyRecommended:=False, CreateBackup:=False
End Sub
If you are trying to save the workbook that contains the macro, you will get a message about not being able to save the vbproject, but I assume the Macro will not be in the workbook you are saving as XML?
|
|
|
|
|
Dear Richard
Thanks For your Reply.
Actually that Worksheet is in .xls format.
I need to Write a Macro that Take the Column value from the Excel Sheet and Generate the Xml File From the particular field...
Thanks n Regards,
Ramya.R
-- modified at 6:36 Thursday 23rd February, 2006
|
|
|
|
|
Hi
What do you want to do with the XML file?
You can write 'text' to a file, in the following format:
<?xml version="1.0" encoding="utf-8"?>
<Sheet1>
<add key="CellA1" value="9.8205" />
<add key="CellA2" value="1473" />
</Sheet1>
You can test this by taking the above, pasting it into notepad, save it. Then change the extension from txt to xml. Then try opening it with the application that requires the file.
You'd have to look at the VBA help to see how to do the FileIO though. (Can help you with VB.Net code only, not VBA ->> Sorry)
|
|
|
|
|
Thanks alot Richard.........
Im new to Xml,Excel and VBA.Your Code Works Fine..
Once again thanks For yor Help....
Thanks n Regards,
Ramya.R
|
|
|
|
|
I have a database in Access 2003 and i set the password for that database.And also connect the database in VB6.0. The code is Cn.open "Driver={Microsoft access Driver(*.mdb)};DBQ=c:\Sam.mdb;pwd=vijay;".vijay is password of my database.But this code not working,
"couldn't find data source and no default driver specifed" this error occured.How do i solve this problem.Reply me soon plz
vijay.
Learn Lot
|
|
|
|
|
Hey, posting the same message three times won't get you an answer any sooner!
Have you looked up the error? What does it say? (Hint: the driver may be incorrect or a wrong path to your MDB file
...Steve
"Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once
|
|
|
|
|
If ODBC is not working , try OLE DB to connect to Access . That is more easy to work .
Divya Rathi
|
|
|
|
|
Hi,
I have a database in Access 2003 and i set the password for that database.And also connect the database in VB6.0. The code is Cn.open "Driver={Microsoft access Driver(*.mdb)};DBQ=c:\Sam.mdb;pwd=vijay;".vijay is password of my database.But this code not working,
"couldn't find data source and no default driver specifed" this error occured.How do i solve this problem.Reply me soon plz
vijay.
Learn Lot
|
|
|
|