|
..and you want the same functionality in the second row cell? Something like this?
For Each row As Windows.Forms.DataGridViewRow In Me.DataGridView1.Rows()
Dim searchVal as String
searchVal = row.cell(1).value
cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = searchVal
next row
That would be flawed too, since you'd still be adding a lot of SqlParameter objects to the command. Can you post the entire method, including the parts where you create and execute the SqlCommand ?
I are Troll
|
|
|
|
|
items search through storedprocedure
the entire code here...
Private Sub getItems()
c.ConS()
c.Cm.Open()
For Each row As DataGridViewRow In Me.ItemsDataGridView.Rows
Dim cod As Integer
cod = row.Cells(0).Value
Dim cmd As New SqlCommand("getItems", c.Cm)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@cod", int).Value = cod
Dim da As New SqlDataAdapter
da.SelectCommand = cmd
da.Fill(dat)
Me.bind.DataSource = dat
Me.ItemsDataGridView.DataSource = bind
Next row
End Sub
so much of happy ending...
|
|
|
|
|
If I understood correctly then you want to use this code to (also) filter on the "name" column? Can you post the source of the stored procedure "getItems"?
I are Troll
|
|
|
|
|
getitems()is the query which retrieves data
i need to filter cod in id column .
i dont know y u want see the code for stored procedure since its just a query
......
select id ,A,B,C from Items where Code =@cod
so much of happy ending...
|
|
|
|
|
Its not clear what you are trying to do, but the code you are using will only iterate each row, if you are trying to also iterate each cell then do the following;
For Each row As DataGridViewRow In DataGridView.Rows
For Each cell As DataGridViewCell In row.Cells
Next
Next
|
|
|
|
|
Your foreach loop enumerates all rows, so you will be adding a parameter (called "@id") for each of them; I don't think that is appropriate, and from your symptom description it seems the first one sticks.
Suggestion: either try using the "current row" rather than all rows, or search all rows for the (first) one that actually holds some data in cell 0.
|
|
|
|
|
Luc Pattyn well i been trying ur idea but if u show me by peace code will be great !!
thanks
so much of happy ending...
|
|
|
|
|
Don't know how it's supposed to work since you did nit tell us that.
What do you expect to be in the Parameters collection?
Try stepping through in the debugger and seeing if your expectations are met.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
zafax_ Wrote:
when i enter a value in the Column cell(0) on first row works fine but the problem is when i enter a value in second,third ... row it doesn't work as it should be.
What is the error description?
Use <pre lang="vb"> Visual Basic Code Here.</pre>
|
|
|
|
|
Using Visual Studio 2008 and Access 2007
I have tried several different ways to track Material Activity. Table MatActivity has a field for MoveFromGUID and MoveFromType as well as Move2GUID and Move2Type. The possible combinations are: From Well to Well; from Well to StorageYard; from StrorageYard to Well and from StorageYard to StorageYard. I tried it with two tables the Well table and a separate Location table but no luck. There are 4 types of wells so I have tried to add the storageyards into the well table and just use a different code for the welltype to indicate it as a storageyard.
The following code gets me the sample data:
SELECT m.MatActivityID, m.TasksID, m.MoveFromGUID, w.Well, m.MoveFromType, m.Move2GUID, m.Move2Type, m.MaterialsID, m.Units, w.WellID, w.WellType FROM Well as w INNER JOIN MatActivity as m ON w.WellID =m.MoveFromGUID;
The following code trying to set another relationship from the well table fails to pull any data:
SELECT m.MatActivityID, m.TasksID, m.MoveFromGUID, w.Well, m.MoveFromType, m.Move2GUID, m.Move2Type, m.MaterialsID, m.Units, wWellID, w.WellType FROM Well as w INNER JOIN MatActivity as m ON (w.WellID = MatActivity.Move2GUID) AND (w.WellID = m.MoveFromGUID);
Do I need to change the table MatActivity? It basically is to document from and to locations and the units of each material being moved. There can be anywhere from several hundred units of one type of material to 30-40 types of material with only a couple of units each. It is related to the Tasks table which provides info on the crew to move the material and the dates and time assigned and actually moved. The Material table provides the description of the material to be moved.
If I need to rethink the process and change the entire table structure to be able to show the actual to and from locations and remainder of data now is the time before I get much further into the project. Any suggestions and assistance greatly appreciated
|
|
|
|
|
that looks like a database question, not a VB/VB.NET question.
|
|
|
|
|
Hmmm ... interesting problem.
Let me offer another view of the situation.
If you create a simple table with:
DateTimeStamp, Status, FromLoc, FromType, ToLoc, ToType
(You can use the status to be: Requested, In-Transit, Complete)
Then you can create 2 other tables:
Locations: (LocID, Description)
MatTypes: (MatID, Description)
With this design, you should be able to answer queries like:
"Which material needs to move from Storage to Well #1 today ?"
"What materials have arrived in Storage over the past week ?"
"What are all the materials that are currently in transit ?"
I'm sure I haven't considered everything, but you should get the idea.
Hope this helps.
David
|
|
|
|
|
That is essentially what I already have with the exisitng tables. Of course there is a lot more information in each table, the well table contains cost center codes, subdivision, longitute and lattitude and is a many to one relationship with the Lease table. The Locations table which I switched and tried to add to the well table still has a cost center and the address of the Location I have placed in the longitude/lattitude fields with the name of the storage yard in the Well field
When I had both tables no problem pulling out the well (which is actually the well number in the particular lease generally coded like: 12-34, 9-1, or 7-50- this relates to the location on a acre gridlines which each square mile of oil field leases are divided into) or the location from the location table. It always seemed to succeed when I went from well to storage or storage to well. But well to well or storage to storage I never got any data - though I have manually created the data so I know I have records for testing purposes.
I was thinking I needed to add something like:
w.well WHERE w.WellID = m.MovefromGUID AND w.well WHERE w.WellID = m.Move2GUID
somewhere in the INNER JOIN's so I am experimenting with that right now. Any other suggestions are certainly helpfull.
Some of the questions we need to ask are:
What materails were moved from storage to wells
What materials moved from wells to storage
What crews moved the materials
Total quantity of each material moved by day by week, etc.
So yeah there is a lot that needs to be gathered and displayed which is why I'm beginning to question my initial database design and wondering if I need to change it dramatically now to save more headaces later.
Years ago with Access 2 and then Access 2000 I finally remember doing something like what I wanted. Using the hlp for Access 2007 is nigh on useless - it is more oriented toward promoting its features than offerring help. I found an old copy of Office 2000 and installed the help and went into it for Access and what I THINK I need is some form of UNION query. That should allow me to keep the seperate tables for Wells and Locations and still be able to pull out either data in wither field. If I run into problems I'll upload a sample of the code later.
Larry
modified on Friday, June 25, 2010 10:07 PM
|
|
|
|
|
At my company we use an instrument which connects to a laptop through ATEN USB to Serial Bridge. What I'm trying to figure out how to do is loop through the COM ports and determine which one the bridge is connected to (similar to the windows device manager that will show the devices name with which COM port it is connected to in parentheses). Anyone have any guidance on how to do this through VB.NET? Even C# code would work as I can probably figure out how to port it. Thanks in advanced.
|
|
|
|
|
There is no standard for this; RS232C defines connectors, pin assignments, voltage levels, bit patterns, but does not describe the content of the data being transmitted. So the best you could do, I guess, is this:
1. connect your peripheral to a known port, open its SerialPort, keep HandShake none;
2. now check the behavior of your periphera;
2a. look for the state of control lines (CDHolding, CtsHolding, DsrHolding);
2b. disconnect and look again;
2c. hopefully there is a difference.
3. optional: check the response on some command; use the device manual!
3a. send a harmless string (best something that would mean "identify yourself"
3b. and watch what the normal reply is.
4. now create code that enumerates the ports, one by one, looking for one (or more) that match the above findings.
|
|
|
|
|
The actual instrument that is connect through the bridge I already know how to communicate with. However, I want to be able to tell when the bridge is plug in to the computer independent of when the instrument is connect to bridge. If I plug the USB-Serial adapter into the computer and look under the Windows Device Manager, under Ports (COM & LPT) is will now list "ATEN USB to Serial Bridge (COM2)", if I unplug it, it will be removed from this menu. So windows definitely knows when the USB-Serial adapter is attached to the computer and which COM port it is plug into. There is no windows service, or something similar , I can poll since I know the name that appears in the window device manager? I was hoping there was something in the System.Management namespace that could do it.
|
|
|
|
|
OK, so I misunderstood.
On USB Windows discovers device insertion/removal by "plugNplay" technology. I don't know the way to interface to that system. I have been looking into the WMI classes such as Win32_SerialPort to no avail.
I do know, at least for some manufacturers, you can make sure the USB-to-RS232C cable always gets the same name ("COM2" in your example), independent of the exact USB port used; I often have had the opportunity to even choose a completely different name, say "MySerial". Not sure on which Windows version(s) this is possible.
If that works for your Windows+cable combination, then by all means choose a unique name, then enumerate all serial ports using SerialPort.GetPortNames (or just try SerialPort.Open).
|
|
|
|
|
Can any one help me how to pass values from one window form to another by clicking on one record in the datagrid placed on one of the window form and passes values to another form and displays the whole record in the text boxes of the form.
Regards
|
|
|
|
|
I think the best way to explain this would be an example. Say you have a collection of people in a DataGrid and when the user selects a particular person, their details should show up in the second form textboxes. Lets use this class :
Public Class Person
Private strName As String
Private intAge As Integer
Public Sub New(ByVal personName As String, ByVal personAge As Integer)
strName = personName
intAge = personAge
End Sub
Public Property Age() As Integer
Get
Return intAge
End Get
Set(ByVal value As Integer)
intAge = value
End Set
End Property
Public Property Name() As String
Get
Return strName
End Get
Set(ByVal value As String)
strName = value
End Set
End Property
Public Shared Function GetPeople() As List(Of Person)
Dim lstPeople As New List(Of Person)
With lstPeople
.Add(New Person("Shantell", 23))
.Add(New Person("Bill", 45))
.Add(New Person("Keith", 36))
.Add(New Person("Jason", 73))
.Add(New Person("Sean", 45))
.Add(New Person("Chris", 90))
.Add(New Person("Peter", 15))
.Add(New Person("Jeremy", 22))
.Add(New Person("Kevin", 67))
End With
Return lstPeople
End Function
End Class
Then in your main form you declare a local instance of your second form at the class level and instantiate it in your main form load event . The code for the first form looks like this:
Public Class Form1
Private People As List(Of Person) = Person.GetPeople 'collection of business objects
Private frm2 As Form2 'declare form2 at class level
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
frm2 = New Form2(People(0)) 'instantiate local form2
frm2.Show() 'make sure is visible
DataGridView1.DataSource = People 'bind DataGridView to collection
End Sub
Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
If People.Count > 0 Then
frm2.RefreshPerson(People(e.RowIndex)) 'call function in form2 to set new selected object
End If
End Sub
End Class
In your second form you declare a local variable of type person and you include a public function to receive any changes to the selected person in form 1.:
Public Class Form2
Private CurrentPerson As Person
Public Sub New(ByVal yourPerson As Person)
InitializeComponent()
CurrentPerson = yourPerson
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
UpdateUI()
End Sub
Public Sub RefreshPerson(ByVal yourPerson As Person)
CurrentPerson = yourPerson
UpdateUI()
End Sub
Private Sub UpdateUI()
txtAge.Text = CurrentPerson.Age
txtName.Text = CurrentPerson.Name
End Sub
End Class
This approach should get you up and running, although personally I would rather encapsulate this in one form, as they are too inter linked in my opinion.Hope this helps.
Happy Codong
|
|
|
|
|
Hi
How can i create a setup file that installs required file if required by the operating system like .Net framework 3.0, 3.5 and like sql 2000 or 2005 .ldf and .mdf files.
I donot understan where to place these files in the setup so that it installs automatically on the specified location and i donot have to copy these files and install them on the specified location.
Please help
regards
|
|
|
|
|
Hi again,
I assume you have created a Windows Forms application, so to include your pre-requisites such as .Net Framework 3.0 or 3.5 you need to go to solution explorer, right click on your project and select Properties. On the tab page that comes up select the Publish tab, then click the Prerequisites button. A dialog box should come up allowing you to select which Prerequisites you want included in the setup. If you want to include the Prerequisites in the same Setup folder as the application setup then tick the radio button Download prerequisites from same location as my application and click OK. This will ensure your selected prerequisites are included with your application setup program. To install extra files such as text or database files etc in a specific location on the target machine, you need to right click your SETUP project in solution explorer and select File System. Under the tab page that comes up highlight File System on Target Machine , and in there you can create folders as necessary, and include whatever you like in those folders, and these will be created on all mechines on which your application is installed.
One thing that you need to think about, and that is Windows permissions, especially on Vista and Windows 7 machines, as the user who installs the application will probably not have full admin privileges therefore it is always better to use Windows default folders where possible.
Hope this helps
Happy Coding
|
|
|
|
|
Hi
Please help, i want when any one clicks on my application icon first loads the splash screen then the login form and then the application. For this i want to use the timer control on the splash screen when the the condition is true that is 5 seconds then load the login form.
regards
|
|
|
|
|
Hi,
I'm writing a steganography app in vb.net, which hides one bmp inside another within the least significant bits.
I want to be able to hide/show the least significant bits to reveal the hidden image. At present this is done via 8 checkboxes. The current code works somewhat but when showing the bits to reveal the second image, the image is visible but is black with no colour information.
Heres an example of my current code to show/hide the least significant bits
Dim b1, b2, b3, b4, b5, b6, b7, b8 As Integer
Dim MaskByte As Integer
If cb1.Checked = True Then
B1 = 1
End If
If cb2.Checked = True Then
B2 = 2
End If
If cb3.Checked = True Then
B3 = 4
End If
If cb4.Checked = True Then
B4 = 8
End If
If cb5.Checked = True Then
B5 = 16
End If
If cb6.Checked = True Then
B6 = 32
End If
If cb7.Checked = True Then
B7 = 64
End If
If cb8.Checked = True Then
B8 = 128
End If
MaskByte = b1 + b2 + b3 + b4 + b5 + b6 + b7 + b8
For x = 0 To Image.Length - 1
If x <= 54 Then
MaskedImage(x) = Image(x)
Else
MaskedImage(x) = Image(x) And MaskByte
End If
Next
CreateBitmap(MaskedImage)
Image() is the opened bitmap converted to a byte array.
It's strange as i can see the outline of the second image, but it contains no colour.
Any help would be much appreciated. Thank You
|
|
|
|
|
Hi,
I'm not sure what you are doing here. Some comments:
1.
you don't need all the b1, b2, b3, b4, b5, b6, b7, b8; you could add to MaskByte right away.
2.
your image may have 4 components: RGB+alpha, so you may be manipulating the alpha/transparency too.
3.
what is the magic about byte value 54?
4.
all your code does is bringing every byte closer to zero; and all-zero is black.
5.
you probably want something like:
For x = 0 To Image.Length - 1
If (x MOD 4) = 0 Then
Image1(x)=Image(x)
Image2(x)=Image(x)
Else
Image1(x)= Image(x) AND MaskByte
Image2(x)= Image(x)-Image1(x)
End If
Next
which still brings things closer to black, but at least it is separating two images.
|
|
|
|
|
Thanks for the reply
The aim of the checkboxes was to allow the user to see the image gradualy transform into the hidden one.
Byte 54 is the start of the bitmap data. Before this, the bitmap contains data such as the file size, resolution, number of colors utilised etc..
I've tried the suggestion but still can't get it to work. The hidden covert image has been encoded into the 4 least significant bits of the original image, so i just need to apply a filter to show the hidden image. I'm just unsure how to acheive this.
I did find some code in matlab that works to extract the hidden image, but i don't now how to convert it to vb.net code.
n = number of bits to utilise i.e. 4 LSB
Stego = Bitmap Image that contains the hidden image
Extracted = Hidden image extracted fromt he Stego bitmap
<br />
Extracted = uint8(bitand(255, bitshift(Stego, 8 - n)));<br />
Thanks for your help
|
|
|
|
|