G_Waddell 131 Posting Whiz in Training

Hi you have added the panel twice once to the Main panel and once to the form:

 'Adding to main panel
 pnlMainPanel.Controls.Add(pnlOrderLine)
 pnlMainPanel.Visible = True
 'Adding to Form i.e. me
 Me.Controls.Add(pnlOrderLine)
G_Waddell 131 Posting Whiz in Training

Hi,

I'm seeing lots of text values being passed in but no string delimiters e.g.

'Like you have
sql ="INSERT INTO MYtable(MyField, MyField2) VALUES(" &MyValue &", " &MyValue2 &")" 

'Example where MyField is a text (string type Field) and MyField2 isnumeric -spot the difference
sql ="INSERT INTO MyTable(MyField, MyField2) VALUES('" &MyValue &"', " &MyValue2 &")"

Also, it should be pointed out that you should really try to use (at the least,) parameterised queries to avoid SQL injection attacks (where nasty people "sneak" SQL commands into your inputs to delete tables etc.)

This link, Working with OLEDB parameters will show you how to use parameters with OLEDB - As you are using a Text command though you can not name your parameters so you must add them in the correct order e.g.

'We don't need to use delimiter as parameters will specifiy their Type
SQL ="INSERT INTO Employee(FirstName, LastName, StartName) VALUES(?, ?, ?)"

dim Cmd as new oleDBCommand(con)

With Cmd
    .CommandType = CommandType.Text
    .Text = sql
    'Now I will demonstrate adding the parameters
    'Using .AddwithValue this will use the value to decide the parameter Type
    .parameters.AddWithValue("@FirstName",Trim(txtFirstName.Text))
    .parameters.AddWithValue("@LastName", Trim(TxtLastName.Text))
    'Now I'll use .Add to specify the type exactly in this case convert to date from a string
    .parameters.add("@StartDate", OleDbType.Date).Value = Trim(TxtStartDate.Text)
End With

Cmd.Execute()
G_Waddell 131 Posting Whiz in Training

Just occurred to me, if there's a space in the filename you may have to do this:

Dim ConFunnelLocation As String

If trim(Form_Funnel_Report.Combo_Funnel_EBU.Text) <> "" then
    ConFunnelLocation = "C:\Database\Funnel\[" & trim(Form_Funnel_Report.Combo_Funnel_EBU.Text) & "].xls"
else
     msgbox("Please select the excel sheet")
     exit sub
end if

ACTUALLY FORGET that - rush of blood to the head!!

G_Waddell 131 Posting Whiz in Training

AndreRet, you missed out the All Blacks (New Zealand for those who don't follow Rugby,) then crush everyone...

G_Waddell 131 Posting Whiz in Training

Hi,

Try doing something like this:

Dim ConFunnelLocation As String

If trim(Form_Funnel_Report.Combo_Funnel_EBU.Text) <> "" then
    ConFunnelLocation = "C:\Database\Funnel\" & trim(Form_Funnel_Report.Combo_Funnel_EBU.Text) & ".xls"
else
     msgbox("Please select the excel sheet")
     exit sub
end if
Begginnerdev commented: Possible rogue space in string. +8
G_Waddell 131 Posting Whiz in Training

It is because you were using an if clause which expects something it can evaluate as true or false

if TRUE Then
    'do this
Else
    'do that
End if

So you where returning a string which the code cannot evaluate as either TRUE or FALSE. What I did was to change the code to basically say:
IF the result of the ScalarQueryCardID is not equal to (<>) an Empty string ("") then

I suspect the code is don't a boolean conversion on the numeric value i.e. 0 = False 1 = true why that would be I don't know - do you have Option Explicit enabled?

G_Waddell 131 Posting Whiz in Training

object.Remove({Index | Key})

In this case object is your listbox, Remove is of course what you are doing to the listbox, now you can either specify the Index i.e. the position of the item in the listbox that you wish to remove or, the Key of the item which really depends on what you have in the listbox.

sub RemovebyIndex (byRef ListItem as String)
dim i as integer = 0
'assume your listbox is a list of strings....

For each item as object in listbox1.items
    if item.tostring = ListItem then
        listbox1.Remove(i)
        Exit For
    end if
    i+=1
next 
end sub


sub RemovebyKey (byref ListItem as String)
For each item as object in listbox1.items
    if item.Tostring  = ListItem then
        listbox1.Remove(ListItem)
        exit for
    End if
next
end sub

I placed the remove by key example in a loop to ensure the target item was in the list.

G_Waddell 131 Posting Whiz in Training

Hi
I suspect it could be this line:
If Me.TbmembersTableAdapter.ScalarQueryCardID(cardid) Then
You say the .ScalarQueryCardID is just returning the CardID as a string? Then I think you should be using:
If Me.TbmembersTableAdapter.ScalarQueryCardID(cardid) <> "" Then

Without knowing more about .ScalarQueryCardID I can't really comment.

G_Waddell 131 Posting Whiz in Training

Hi,

I think you are applying the cascade delete to the wrong table.

You are altering the table Sample Customer to include a Foreign Key (Sample_Note_No) linked to Sample.Sample_Note_No but you are then saying if the record in Sample Customer is deleted, delete the corresponding record in Sample.

Therefore SQL is stopping you because if you did this you would delete the record in Sample and potentially leave orphaned records in the Sample Customer table (assuming a One to Many relationship, which SQL server is.)

I think you want to apply the cascade to the Sample Table so if you delete the record there you delete any child records in Sample Customers.

G_Waddell 131 Posting Whiz in Training

Hi,

Have you tried this? Do you have any code? lots of examples here and on MSDN website about using datagridviews..

G_Waddell 131 Posting Whiz in Training

I think the clue is in the user name....

G_Waddell 131 Posting Whiz in Training

Hi,

Looking at your code, I can only see two possible reasons for a syntax error:

  1. You are passing strings in for every field you are updating, are all the fields in the database definately string types?
  2. txtUser.text is either blank or has a value that doesn't match to a record in the table. i.e. there is no matching record in the table to update.

There could be something else going on but thats all I can see so far. As Reverend Jim says bedugg the code and do a watch on sqlupdate. You could try copying the sql produced in sqlupdate into your access DB querybuilder (in SQL mode,) and see if it highlights any syntax errors.

G_Waddell 131 Posting Whiz in Training

Management is like monkeys sitting in the tree. The monkey at the top looks down and sees smiling faces. The monkey at the bottom looks up and sees just a load of....

I'll let you guess the rest.

G_Waddell 131 Posting Whiz in Training

Would you walk into a bakers and ask for a free loaf of bread?
Would you expect a builder to put up a wall for nothing?
Would you ask an accountant to do your tax audit for free?
Then why ask someone here to do their job for you for free?

G_Waddell 131 Posting Whiz in Training

Hi,

Does this not work?

Dim mag As New Magento.ecommerce
Dim Stockcodes As New List(Of magento.clsStockcode) 
Stockcodes = mag.ReturnNewStockodes("admin", "password")

If not, try replacing magento.clsStockcode with mag.clsStockcode

G_Waddell 131 Posting Whiz in Training

Ireland are going into the Scotland game at Murrayfield without Sexton, Zebo (injuries) & Healy (suspension). McCarthy is rated doubtful, and Sean O'Brien (tight hamstring) is being monitored.. that's a good number of players to loose... I fancy Scotlands chances.

G_Waddell 131 Posting Whiz in Training

Hi,

If it returns a list, you should be able to navigate through it:

Dim Stockcodes As New List(Of magento.clsStockcode)
dim Stockcode as magento.clsStockcode
dim code as string

'Get your stockcodes
If Stockcodes.items.count > 0 then 'I think it's items.count, could just be .count
    For each Stockcode in StockCodes
        'work with the stockcode e.g.
        code = Stockcode._StockCode
    next
end if
G_Waddell 131 Posting Whiz in Training

Hi,
Do you have access to the source code of the class? Is the function ReturnNewStockodes public in the class? What should the ReturnNewStockodes return i.e. a single clsStockcode or a list of them?

Stockcodes = mag.ReturnNewStockodes("admin", "password")

Would imply a list of clsStockcodes where if you only expected a single one you would do something like this:

Stockcodes.Add(mag.ReturnNewStockodes("admin", "password"))

Also while I was typing I noticed you had used ReturnNewStockodes not ReturnNewStockCodes - just in case there is a typo...

G_Waddell 131 Posting Whiz in Training

Hi, Sorry I've never actually done any work with SNMP so I would n't be much help in that regard - is there any documents that came with the hardware? Did you try google?

G_Waddell 131 Posting Whiz in Training

It really depends what you are doing and where the app will run.

For instance, if you've got ASP.net pages on a server in a DMZ opened out to the Internet you may prefer to avoid using windows security and opening your domain up to the DMZ in which case if you only open SQL Port use a SQL user AND FOR THE LOVE OF GOD NOT SA sorry, just found some code where a junior programmer had used the sa user in their test/ development machine then deployed it live to a web site @@@!!""""£££$

I've got into the habit of doing it my way and it is just second nature now.

G_Waddell 131 Posting Whiz in Training

Hi,

For people using a Microsoft SQL Server database:

  1. Don't build queries on the fly - use only stored procedures, it forces you to use parameters and leads on to point two:

  2. Use a dedicated SQL account for your application that has only has execute rights on the stored procedures you have written.

By using a dedicated SQL user account with only rights to execute your stored procedures even if a SQL injection attack got to your SQL server, the user account it is running under has no rights to access, alter or delete anything on the database server therefore inbuilt SQL security will come into play.

i.e. instead of this:

MyCommand.CommandText ="SELECT * FROM MyTable WHERE (MyID='" & trim(Textbox1.text) &"')"

Do this

Mycommand.CommandText = "MyStoredProcedureName"
MyCommand.CommandType = CommandType.StoredProcedure
MyCommand.Parameters.AddWithValue("@MyID", trim(Textbox1.text))

And on your SQL Server:

CREATE PROCEDURE MyStoredProcedure @MyID bigint AS
SELECT * FROM MyTable WHERE(MyID = @MyID)

The more layers of security you add, the more difficult it becomes to cause mischief...

G_Waddell 131 Posting Whiz in Training

Use settings...

G_Waddell 131 Posting Whiz in Training

Hi,

I can't see any loop in your code...

What I see is the following:
1. You only do anything with the recips array when intReply = 250
2. When you go into that bit of the code, recipCount = 0 (unless changed somewhere else)
3. You build your command then send your data
4. You then check if the is the upper bound of Recips and if it is you alter the command (but you already sent it..)
5. Now you increase the recipCount by one
6. Then the rest of your sub routine is missing so I assume you've finished in which case you never actually do anything with the next recipient, unless you are calling the routine in a loop.

G_Waddell 131 Posting Whiz in Training

Hi,
What errors do you get and where did you get them?

You need to add a reference in your project to adventnet which I assume is the software that communicates wih your card. - there should be a .dll file somewhere on your machine called aventnet if that is the software that came with your card.

To add a reference you can either open the project properties page and then the References tab Add Reference and browse for the .dll file

OR

In solution explorer ensure the show all files option is on and open the References folder, Right click on it and Add Reference then again browse for the dll file.

G_Waddell 131 Posting Whiz in Training

I think you want this:

IF not(EVENT_NUMBER.Text ="" Or person.Text ="") And Event_ASSOC2.Text <> "Stolen" then
    'Call your create excel file
ElseIf Event_ASSOC.Text ="Stolen" And ORIGINAL_VALUE.Text =""  then
    messagebox.show("Property listed as stolen requires a value", "Warning", Messageboxbuttons.ok, MessageBoxIcon.Error)
ElseIF EVENT_NUMBER.Text ="" Or person.Text ="" then
    messagebox.show ("Person and Event Number Fields ned to be completed", "Error!", Messageboxbuttons.ok, MessageBoxIcon.Stop)
Else
    'if Event_Number and Person are filled in and Event_Assoc2.text ="Stolen" but Orignal_Value.Text <>""
    'You'd end up here...
End if

I don't see the benefit in going to a case block. You'd still end up with nested ifs:

SELECT CASE Event_Assoc.text
    Case "Stolen"
        if ORIGINAL_VALUE.Text ="" Then
            'Messagebox
        Else
            'do what?
        End if
    Case Else
        if EVENT_NUMBER.Text ="" OR person.Text ="" then
            'messagebox
        else
            'call your Excel file
        end if
End Select

So why not just use a big If block?

If Event_Assoc.Text ="Stolen" Then
    IF ORIGINAL_VALUE.Text ="" then
        'messagebox
    End if
ELSE
    if EVENT_NUMBER.Text ="" OR person.Text ="" then
            'messagebox
    else
           'call your Excel file
    end if    
End if
G_Waddell 131 Posting Whiz in Training

Hi,
You need to apply an UPDATE statement. You can either define one for your adapter via the UpdateCommand property (OLEDB DataAdapter.UpdateCommand) Or run an Update statement via a OleDbCommand

G_Waddell 131 Posting Whiz in Training

Hi,
I don't think Scotland will win it unless there are some fairly big upsets BUT I think for the first time in ages I'm seeing signs of improvement, maybe it's the new coaches. I'm happy to see improvement this year and mount a challenge next year.

France are certainly on course for the wooden spoon but you never know what French team could turn up in their remaining games, they will certainly be p'ed off at loosing at home.

If Wales get back to some form they could do Ireland a favour against England...

Italy sorry but I think they're depending on France playing badly to avoid the wooden spoon.

I think there is still a chance Ireland could win and that England don't have it all won yet although they are the only team who can do a grand slam.

G_Waddell 131 Posting Whiz in Training
G_Waddell 131 Posting Whiz in Training

English, Some Scots dialectics (not Gaelic), some French and currently learning Irish (Irish Gaelic,) from my wife and child (I'm from Scotland but I live in Ireland and my kid goes to Gaelscoil) also my dog only responds to Irish commands (We got her as a rescue and noticed one day after much frustrated attempts to train her)

G_Waddell 131 Posting Whiz in Training

Hmmm Interesting - from years of watching the Muppets Show I can inform you that Pigs in Space seem to bumble from one funny adventure to the next... While Swedish Chefs are obsessed by chickens

G_Waddell 131 Posting Whiz in Training

I've never mixed up Canada and the USA - is that a common misconception? Although I can clearly understand why it would annoy either party. Canadians can spell properly for one thing! e.g. colour...

I can also see how a non North American may hear a Canadian accent as an American one but that is more to do with being less familiar with the accent or the numbers of Canadian actors in US made programs?

G_Waddell 131 Posting Whiz in Training

No Worries, Sometimes it just needs someone else to take a look at the problem...

G_Waddell 131 Posting Whiz in Training

I think he is running the UPDATE to test if he has opened Access in Read Only mode.

As Ancient Dragon says, the data will only be altered if you run an UPDATE, INSERT or DELETE query so don't!

G_Waddell 131 Posting Whiz in Training

Hi,

You just need to modify your code slightly... in your SQL string, LIKE expects a value after it, you wish to use the parameter @Input to supply this value but because you are placing the parameter inside a string '%@Input%' the SQL literaly thinks find a record where lenscode contains "@Input" i.e. it does not read it in as a parameter...

So you can modify your code as follows:

TempCommand.CommandText ="SELECT Lenscode FROM Products WHERE (Lenscode LIKE @Input)" 

'I assume you pass the value into the input so I'll use a variable for you. 
'In your example,  MySearchValue =5
TempCommand.Parameters.AddWithValue("@Input", "%" &MySearchValue &"%")

As an alternative, it may be possible to do this - but I've never tried it...

TempCommand.CommandText= "SELECT Lenscode FROM Products WHERE (Lenscode LIKE '%' + @Input +'%')
G_Waddell 131 Posting Whiz in Training

After six pages I'd like to point out that I now understand the need for automatic doors!

If you ask me who I am:

  1. I'm George
  2. I'm Scottish
  3. I'm British
  4. I'm a European
  5. I'm a Human

I'm not now or will never be English.

Quick edit: I've nothing against the English really just I'm not English.
1536 - Act of Union joins England and Wales

1707 - Act of Union unites Scotland and England, together with Wales to form the Kingdom of Great Britain.

1801 - The Irish Parliament voted to join the Union. The then Kingdom of Great Britain becomes the United Kingdom of Great Britain and Ireland.

1922 - Name changed to United Kingdom of Great Britain and Northern Ireland, when most of the Southern counties in Ireland choose independence.

P.S. some of those "acts" came at the point of a bullet (or lance..)

G_Waddell 131 Posting Whiz in Training

Hi raajsj,

I think what JorgeM is sugesting is that you have a go at coding it and let us know where you hit problems...

start by writing breaking down what you want to happen into a flow chart then for each stage of the flow chart try to write some code that will carry out the task.

G_Waddell 131 Posting Whiz in Training

Hi
You may want to use a dataadapter instead of a datareader. Datareader is a forward only connected recordset. Datadapter will give you access to a dataset which alows you to go back and forth and is disconnected.

G_Waddell 131 Posting Whiz in Training

Hi That error you have looks like you are passing a parameter into SQL that is of the wrong type or length...

SQL will try to convert but may not be able to do it e.g. passing in a string into a date if SQL can convert it then there is no error but if it can't you get that message.

G_Waddell 131 Posting Whiz in Training

WOW thats a lot of code... Your opening file stream your runnning updates the lot... Not sure why your opening a file stream though.

Anyway i'll give you a basic break down of what I would do:

On my form have the datagrid with a column for each field in the Employee table hiding any columns of fields I didn't want the users to change. I'd have the edit mode set to edit programatically and Multiselect to False.

Also On my form I'd put a hidden textbox for the EmployeeID and textboxes for any Employee Fields that the user can update.

Then I'd add an edit button when the user hits the button, the routine checks for a selected row in the datagrid - it then takes the field values from the selected row (selectedrows(0)) and populates the textboxes including the the employee ID value to the hidden employee ID box

Next Id have a save changes button and this would carryout the actual update. It would read the values from the textboxes and place them into my update statement ensuring the Where clause in the query got the employee ID value from the hidden textbox (not Datagrid) It would then reload the changed data into the datagrid.

chdboy commented: I have made an textfield(Hidden)and point my where clause to it,it has EmployerID field number to it....thanks a lot for the Idea +1
G_Waddell 131 Posting Whiz in Training

Hi
Unfortunately there is no try catch block in VB6... You have to go back to the good old fashioned On Error

Do you want to handle the error in your code? or are you trying to figure out where it occurred?

If you're handling in the code you have two choices:

'Example of sub routine with GOTO
sub myGotoRoutine()

On Error Goto Err_Handler
'..... do what ever
Exit sub
Err_Handler:
'What do you want to do with the Error?
exit sub

'Example of sub routine with resume next
sub myNextRoutine()
On Error Resume Next
'Doing something that could lead to an error    
if Err.Number <> 0 then
        'Handle error
        Err.clear
End if
'...
Exit sub

The On Error Goto Option means that if there is an error go directly to the marked line of code. In the example I've done if there is an error anywhere in the sub routine then the code jumps down into my error handler if not, it will hit the line Exit sub beforehand and not go in.

The On Error Resume Next means exactly that, if there is an error, carry on to the next line of code. In my example I trap and handle the error on the next line.

If you are trying to figure out where it happens, you need to put brek points in your code and step through it.

As an educated guess, I'd say the code is trying to insert a record into a …

G_Waddell 131 Posting Whiz in Training

Hi,

On your database server, run the SQL configuration manager. It will be under (depending on Operating System,) Start > Programs > Microsoft SQL Server 2008 R2 > Configuration Tools > Configuration Manager.

When it opens up, under the SQL Server Configuration Manager (Local) expand the SQL Server Network Configuration option then the Protocols for MSSQLServer option. Ensure that the TCP/IP option and Named Pipes option are both set to Enabled

This will allow SQL Server to take incoming connections from your LAN.

Now use a SQLAdaptor or SQLDataReader with the appropriate Connection string and pull back data from it. Or maybe a SQL command and push data out to it...

Nearly forgot, to say if your database server has windows Firewall enabled you will need to open up port 1433 to allow SQL traffic through.

G_Waddell 131 Posting Whiz in Training

Why stop at SQL 2008? We have clients with SQL 2012...

G_Waddell 131 Posting Whiz in Training

Hi
This wouldn't call an error but I was wondering why you did this:

If File.Exists(path) = True Then
    Exit Sub
ElseIf File.Exists(path) = False Then
....
End if

Surely if File.Exists is not true then it is false... i.e. why not just "Else" I'm just wondering would the way you've done it not them make another call out to the system.IO to find out if the file was there when you've already established that it isn't?

Not getting at you just curious.

G_Waddell 131 Posting Whiz in Training

Hi,
I always install SQL first. I do this because in the past I got caught out by installing VS first then trying to install SQL server and Management Studio and I couldn't...
I think it may have been on VS 2005 but it could have been 2008.

Anyway it had SQL plugins included with it for SQL CE but they were SQL Service Pack 2 and although it let me install actual SQL it gave me error messages because there was a newer version of SQL installed and Management Studio would not launch.

I thought if I uninstalled VS then tried installing SQL first but it had left the SQL plugins behind - I ended up spending an afternoon going through registry entries trying to nuke them out of it so I could install SQL Server... so now I always put SQL on first.

G_Waddell 131 Posting Whiz in Training

Hi,
Where do you actually write the entry to your setting? Are you saving the updated setting?

G_Waddell 131 Posting Whiz in Training

Hi,

Not sure what you ment by that last comment?

Do you mean you are coding the same code on two different machines?

Do you have a source code versioning application such as SourceSafe or SVN? You would need something like this to check in and out the source code from a central repository to the different machines that you code on. Your code is being held locally on the machine you develop on if you make a change on machine A and don't synch/port that change to machine B then your code is out of step.

If you mean you made the change and have two machines running the program but the change only appeared on machine A it may mean you have to redeploy (Or reinstall,) your program to machine B

G_Waddell 131 Posting Whiz in Training

Hi
This site will give you the connection strings to required to connect to most databases, ConnectionStrings.com.

You need to connect to the database via ADO (in this case using SQL native connections) - I'm assuming as you have posted on a VB.net forum you are using VB.net as your programming language.

If you've never connected to a database before you may wish to lookup the following on Google or the MSDN site for examples:

  • SQLDataAdapter
  • SQLDataReader
  • SQL Command
  • SQL language

As Lethugs pointed out, you will need to allow/ensure that your SQL server accepts incoming TCP/IP connections (you communicate over your LAN using TCP/IP) and if your SQL Servers server has a firewall you will need to allow Traffic through the SQL Port (1433) If you let us know which version of SQL Server you are using (2005, 2008, 2012?) someone will be able to to show you where to check these settings.

G_Waddell 131 Posting Whiz in Training

@malarsevli - do you just want some sort of random ID containing letters and numbers?
Or is it some sort of password generator you are trying to get?

If you have a SQL database, it has a field type GUID which will generate a randomish ID that uses numbers and letters (it is based on the computers network card and CPU Time)

G_Waddell 131 Posting Whiz in Training

Hi
How are you using the Update? Are you specifying the Update as the updagte command on the datasource? Or are you doing it in reponse to a button click or something? Could you show Us the code you are using to fire the update event?

Sorry unfortunately SQL Profiler doesn't come with the Express edition of SQL :(

datagridview.SelectedRows will given you a collection of the rows that are selected on the datagridview so if you just want to update the selected rows you'd do something like this:

Dim DGVRow as DatagridviewRow
Dim EmployeeID as integer


For each DGVRow in MyDataGridView.SelectedRows
    EmployeeID = DGRow.Cells(0).value

next

BUT Looking at your code it seams to me your edit is not actually being done in the grid but on textboxes?

In which case, Why not have a hidden employeeID textbox that you populate with the employee Id of the selected row you are editing? Run your update statement using what you know is the correct ID form the textbox and remember to reload the grid.

G_Waddell 131 Posting Whiz in Training

Hi
Try this mod and see what happens:

 While myReader.Read
     SPTexbox.Items.Add(myReader("playernam"))
     SPnumTexbox.Items.Add(myReader("plnum"))
 End While
 conn.Dispose()

i.e. remove the limit on the item count and see if the row appears...