samir_ibrahim 58 Junior Poster

@Jim
I don't agree on the above statistics and I don't agree on your comment on my code. Why?

First, It seems the one who made this statistics like the slow motion activity because he didnot mentioned "Speed and performance". Where I will use code written in machine language (01) in my project if it proves its faster by > 20% from a code that easy to maintain.

Second, my code is simple to people who use alot of database manipulation

Third, I made a test on a SQL Server table I had, I get 10,000 rows where I have 2477 rows has p_fcat = 10 and tried these both codes

Me.dataGridView1.DataSource = DT1
Dim sw As New Stopwatch
sw.Start
DT1.AsEnumerable.Where(Function(f) f("p_fcat") = 10).ToList.ForEach(Sub(s) s.Delete)
sw.Stop
Dim ts As TimeSpan = sw.Elapsed
Button4.Text = ts.Minutes.ToString + ":" + ts.Seconds.ToString + ":" + ts.Milliseconds.ToString

result = 0:0:480

dataGridView1.DataSource = dt2
Dim sw As New Stopwatch
sw.Start
For i As Integer = dt2.Rows.Count - 1 to 0 Step -1 
    Dim value = dt2(i)("p_fcat")
    If value = 10 Then
        dt2.Rows.Remove(dt2.rows(i))
    End If
Next
sw.Stop
 Dim ts As TimeSpan = sw.Elapsed
Button5.Text = ts.Minutes.ToString + ":" + ts.Seconds.ToString + ":" + ts.Milliseconds.ToString

result : 0:2:459

Lambada is faster than loop by 5 times

I will chose Lambada in my projects if I don't know anything about it even if I don't understand how it work (but I do :) )

samir_ibrahim 58 Junior Poster

@Reverend

Sorry if you consider this code complex and hard to maintain but is very easy, and downvote? I guess i need a lawyer lol

What you see I consider it as one of Lambada power to deal with rows in datatable in very effecient way that is the same as :

Dim RowsToDelete =  dt.select("Qty = 0")
For each RowToDelete In RowsToDelete
    RowToDelete.Delete
Next

Althought I like @Minimalist idea (+1) of making loop reverse, but sometimes you need to select records that cannot be done by doing loop, Lambada is your choice.

Any way, where is my lawyer?

samir_ibrahim 58 Junior Poster

you can try the below

DgvStock.DataSource = dt

dt.AsEnumerable().Where(Function(r) r.Field(Of Integer)("qty") =0).ToList().ForEach(sub(x) x.Delete())
samir_ibrahim 58 Junior Poster

You can embed Excel and Word inside vb/c# form. I also suffered alot to get a working a code where I found alot of posts says that web browser can embed excel but that did not work with me

Here is my way

Add a Form, Button, Panel
This will display Excel inside the panel

Add Refrence to : Microsoft Office ?? Object Library

Imports Microsoft.Office.Interop

Public Class Form1
    Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
    Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    Private Const WM_SYSCOMMAND As Integer = 274
    Private Const SC_MAXIMIZE As Integer = 61488
    Private Sub btnShowExcel_Click(sender As Object, e As EventArgs) Handles btnShowExcel.Click
        Dim sExcelFileName = "C:\myfolder\myexcel.xlsx"
        Dim oExcel As New Excel.Application
        oExcel.DisplayAlerts = False
        oExcel.Workbooks.Open(sExcelFileName)
        oExcel.Application.WindowState = Excel.XlWindowState.xlMaximized
        oExcel.Visible = True

        SetParent(oExcel.Hwnd, pnlExcel.Handle)
        SendMessage(oExcel.Hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
    End Sub
End Class
samir_ibrahim 58 Junior Poster

Do this test when you save.

msgbox(AccessonbookTableAdapter.Adapter.UpdateCommand.CommandText)

Is it empty?

samir_ibrahim 58 Junior Poster

There could be some security restriction if you install the access database in c:\program file\your_folder or c:\program file (x86)\your_folder . If you do, try to to give full access to the folder where your data reside by right click on the folder and press properties >> security tab.

samir_ibrahim 58 Junior Poster

You are using 2 Tables, reading the row of the first table, then reading all the rows of second table, but you are not using any value from any row in any table

In your IF CONDITION you have (IF TEXTBOX.TEXT = STRING), the table rows loop is useless if you not reading the value from tables..

So, what you are trying to do exactly?

samir_ibrahim 58 Junior Poster

You are welcome :)

samir_ibrahim 58 Junior Poster

your query will not return the columns name "locid,locname,locadd", it will return 1 column as you put in the query

your only column is MAX(locid), and since you didnot specify the a name by using MAX(locid) as FieldName, its hard to tell what will be the column name.

You are getting 1 column contains Max(locid), so to get it correctly

dtr.Read()
xt_locid.Text = dtr(0).ToString

and remove the other two since they don't exist.

samir_ibrahim 58 Junior Poster

bs_detail.Position = bs_detail.**Find**("id",RoomNoInListbox)
The above line of code I post it earlier will do all that for you since you using bindingsource.

The Find() is a method in Bindingsource

samir_ibrahim 58 Junior Poster

Dragging data source to the form will create a bindingsource for you (Let assume that the bindingsource name is bs_detail)

Use the Find("FieldName",FieldValue) to find the required row depending on the listbox selection, so basically you should not code more that the below

I used "ID", change it to the field name you have in your table

Private Sub lstListBox1_SelectedIndexChanged( sender As System.Object,  e As System.EventArgs) Handles lstListBox1.SelectedIndexChanged

        Dim RoomNoInListbox = Me.lstListBox1.SelectedItem()(0)

        bs_detail.Position = bs_detail.Find("id",RoomNoInListbox)
End Sub
samir_ibrahim 58 Junior Poster

You can use the dataset to hold your table, then dataadapter will handle your table changes and compare the data since the time you load the row from table and when you update the row to check if any other user changed during the time you load the row (that is "optimistic concurrency")

row lock is useful to prevent many user changing the same row at the same time, but you should know when to lock the row (not every select statement should lock the row) you can tell that in your program diagram.

That how it works with SQL Server, not tested with MySQL, but the idea should remain the same

samir_ibrahim 58 Junior Poster

Does the information in the Listbox (retreived by SQL Query) is using the same table shown in picture? or there is 2 (table and query)?

samir_ibrahim 58 Junior Poster

you can do it like that

Public Class myclasss
    Property one As Double
    Property two As Double

    Sub test1
        one = 12
        two = 10
    End Sub
    Sub test2
        Dim three As Double = one
        Dim four As Double = two
    End Sub
End Class
samir_ibrahim 58 Junior Poster

sqlda.SelectCommand = sqlcmd -- the error is pointing here

How did you declared sqlda and salcmd?
there should be in your declaration Dim sqlda as New ...... and Dim sqlcmd as New ....

samir_ibrahim 58 Junior Poster

I clear the table, fill the table and let the bindingsource and binding unchanged, like that

' Clear the grid
mydataset.Tables("payments").Clear
' Fill the grid
myDA.Fill(mydataset, "payments")
samir_ibrahim 58 Junior Poster

Try this
Remove the msgbox()
put this line instead

if cmbAssocID.SelectedValue Is Nothing then Exit Sub
samir_ibrahim 58 Junior Poster

I believe that you had used SQLClient() and you should use
SqlServerCe.SqlCeConnection

Try that.

samir_ibrahim 58 Junior Poster

There is a lot of useful tutorial, I found this, I suggest you study it, and ask question about problem that my occurs to you.

1- A Basic ADO.NET Tutorial in Visual Basic.NET

2- A Basic VB.NET ADO.NET Tutorial: Adding, Deleting, and Updating

Don't forget to download the example.

samir_ibrahim 58 Junior Poster

>How insert , Edit and update data in datagrid?

For database operations use ADO.NET data provider classes.

Is that an answer :P, I thought you will post tutorial video from 5 parts :icon_lol:

Just wonaa say Hi to you. :)

samir_ibrahim 58 Junior Poster

Not sure if it is the right way but
- I read dll created by .net does not need to be registered.
- if regsvr32 did not work try regasm

http://msdn.microsoft.com/en-us/library/tzat5yw6%28VS.71%29.aspx

samir_ibrahim 58 Junior Poster

Any insight into how I can locate a programs path would be immensely helpful.

Get Add Remove Programs List

samir_ibrahim 58 Junior Poster

Sorry if I am not making it clear, No the program trying to access the dll is not another dll the third party software requires a DLL to contain a function named UserInstruction. I know how to create a dll and function named UserInstruction but I need the function to become accessable outside the bounds of the dll. Think the technical term for this is exporting the function.

And you are still not clear for me :)

I know this is possible in C or C#

Well, I know how to declare a variable in C (not all :D)
but what concern to C# any thing C# can make vb.net can make.

Basically the third party software opens a dll and searches for a function called UserInstruction.

you mean the dll is exist? and you want to use it?

samir_ibrahim 58 Junior Poster

Since no one jumps in, let me ask you

Hi all,

Got a real pain of a problem. Im using vb.net to write a dll for third party software (PreS) that has no COM interface but allows functionality to call DLL's.

do you mean that the dll you are creating suppose to get interact with another dll?

exporting functions isn't avaliable in framework.

What do you mean by "exporting" ?

samir_ibrahim 58 Junior Poster

I like the current design although i am not an old user, I begin using Daniweb as my programming forum since 1 years only, since I was vfp programmer.

The design is good to the eyes (my eyes at least) and the navigation is simple.

I liked the new rating system. I guess it will take it is effect and it will show up the important of it when there is a discussion and 2 people expressing there ideas about one subject, they can see which opinion is getting more approval.

I just had one problem with the current design.
I am not able to see the Hybird style of the sheet, where I was using it to post an answer to specific user. I am not saying that you should return it back, but what is the good way to post to specific person after -let say 2 days- where there is many posts already there. Quote his entire post in my response?

samir_ibrahim 58 Junior Poster

Thank you cscgal for getting back my request.

Keep the nice improvement for this site.

samir_ibrahim 58 Junior Poster

I want to learn VB or VB.net and want to use for my website (ASP.net)

I would say learn asp.net which is 70% of it vb.net

I would add my approval to what Vineeth K has said.

in my opinion, Vb.Net is nothing more than "vb6 + Powerful IDE + Smart Intellisense + 10000 built in function"

VB was legend and it is still used in VBA Application where Vb.net is not used in that area widely yet.

samir_ibrahim 58 Junior Poster

Anyone else done this before?

I did not work in excel plug-in or know how it works but you can use this to hide the sheet

Imports Excel = Microsoft.Office.Interop.Excel

Dim ex As new Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
wb = ex.Workbooks.Open("c:\test.xls")
ex.Visible = True
ws = wb.Sheets("sheet1") ' change the name that you want to hide
ws.Visible = Excel.XlSheetVisibility.xlSheetVeryHidden  ' Read the comment The user cannot un-hide this sheet
debug.Print (ws.Range("A1").Value) ' You can still read value from it
samir_ibrahim 58 Junior Poster

I can tell that you are answering questions and you are very active in many forums, I cannot see Serkan activity in vb I guess he is C# Guy.

Keep going.

samir_ibrahim 58 Junior Poster

Hello Ichibang

I had struggled with this issue for a while but finally I made it, here how things work.

First open the DataSet in the designer, click on the table you are working on, click on the TableAdapter and check if it has Update command, check the commandText and if the Parameter is correct.

if you are using BindingSource with the DataGridView, you should code (my code in vb but i guess you know what I mean)
CustomerBindingSource.EndEdit
ShugahDA.Update(shugahCustomerDS)

If you are not using BindingSource
ShugahDA.Update(shugahCustomerDS)

ShugahDA.Update() <-- I am not able to write it like that in my vs2008 unless ShugahDA is declared as oledbDataAdapter.

Below the form that you are working with, check if there is CustomerTableAdapter.

I am little lost of what you are using exactly, a oleDataAdapter created programatically or with Dataset Created at design time ?

samir_ibrahim 58 Junior Poster

Thats funny because everything I said works fine here but your code apparently is not

What that suppose to mean?

ou can be lazy and save typing two whole words and spend hours asking for help because of it or you can learn to program correctly

lazy has nothing to do in here, it is a fact.
1- Dim x = "A"
2- Dim x as String
x = "A"
3- Dim x as String = "A"

Are Identical 100% regarding the debugging and execution.

If you are referring to

Dim x = "1"
Debug.Print (x+1)

will give 2 if Option Strict is off, that is another matter.

03) Use prefixes in your controls & variable names

I had asked this question before, 3/4 MVP advice against it, althought I was using it extensively in VFP, since in VFP this is allowed.

Local I as Integer
I = "Samir"

But I got the advice not to use any kind of prefexing.

samir_ibrahim 58 Junior Poster

Also it is not good programming practice to dimension variables without explicitly stating the datatype.

Change "Dim _FieldType =" to "Dim FieldType As String =".

I had tested that before, and it gives the same effect in all aspect.

dim x = "1"
x 'just type x and wait the intellisense to showup it will tell you that x is declared as string

Also you should always put a "Case Else" in your Select Case statement; even if there is no coding under it. Otherwise an error will occur if your search criteria isnt found in any of the other Case statements.

Good Idea.

Thank you for your input.

samir_ibrahim 58 Junior Poster

Replace or with a comma

Case "System.Int32", "System.Int64"

Hi Tom

I had take the or with me from VFP I guess :)

I had test example and it did not give right result neither a error message

Dim A = "1"
Select Case A
Case "1" or "2"
    MsgBox ("1 or 2")
Case "3" or "4"
    MsgBox ("3" or "4")
End Select

but when I replace it with

Dim A = "1r"
Select Case A
Case "1r" or "2r"
MsgBox ("1r or 2r")
Case "3" or "4"
MsgBox ("3r" or "4r")
End Select

I gives the error message. so I guess I did not test deeply.

Thank you.

samir_ibrahim 58 Junior Poster

After that it'll fire the DataAdapter.Update() method.
ShugahDA.Update(shugahCustomerDS)

Are you using Binding source?

this.oleDbUpdateCommand1.CommandText = "UPDATE Customer\r\nSET CustName = ?\r\nWHERE (CustID = ?)" + "";
this.ShugahDA.UpdateCommand = this.oleDbUpdateCommand1;

That is not valid commandText, no \r\n should exist
it should be

this.oleDbUpdateCommand1.CommandText = "UPDATE Customer SET CustName = ? WHERE (CustID = ?)"  

in line 8 which is the last line of your code, you are setting the updatecommand to the "ShugahDA" Data Adapter, that will not fire the update. Are you doing it else where?

samir_ibrahim 58 Junior Poster

Since you are filling statementResult, and updating rows in statementResult and then you are using for each row loop for the same statementResult, why don't you update the datatable?

SQLDataAdapter.Update(statementResult)

samir_ibrahim 58 Junior Poster

I am creating a form that will filter datagridview while typing in a textbox. I came through this error and I would like to know why is occur.

Dim dt As DataTable = Ds_Pos.Employees
        Dim dv As New DataView(dt)
        'findcrit is declared as string public and it contain a field name stored in combo
        Dim _RowFilter As String = ""
        Dim _FieldType = dt.Columns(findcrit).DataType.ToString

        Select Case _FieldType
            Case "System.Int32" or "System.Int64"
                _RowFilter = "convert(" & findcrit & ", 'System.String') like '" & Me.TextBox10.Text & "'"
           Case "System.Double"
                _RowFilter = "convert(" & findcrit & ", 'System.String') like '" & Me.TextBox10.Text & "'"
            Case "System.String"
                _RowFilter = findcrit & " like '" & TextBox10.Text & "*'"
        End Select
        dv.RowFilter = _RowFilter
        EmployeesDataGridView.DataSource = dv

I got error in line 8
Conversion from string "System.Int32" to type 'Long' is not valid.

Now If i change the above Select Case to

Select Case _FieldType
            Case "System.Int32"
                _RowFilter = "convert(" & findcrit & ", 'System.String') like '" & Me.TextBox10.Text & "'"
            Case "System.Int64"
                _RowFilter = "convert(" & findcrit & ", 'System.String') like '" & Me.TextBox10.Text & "'"
            Case "System.Double"
                _RowFilter = "convert(" & findcrit & ", 'System.String') like '" & Me.TextBox10.Text & "'"
            Case "System.String"
                _RowFilter = findcrit & " like '" & TextBox10.Text & "*'"
        End Select

It works fine

I know the Select Case can accept the or but why not in the above code?

samir_ibrahim 58 Junior Poster

none of them, the key is to drink monster energy drink. sknake is the official sponsor of monster.

Is that so? ummm, and you 2 are friends? so that drink is giving both of you extra ability to see hidden things. Is that also the reason why both of you had so many solved thread :P

I hope this drink is not so powerful so you begin to answer questions not being asked yet :icon_exclaim: :icon_lol:

samir_ibrahim 58 Junior Poster

Use your google-fu

Google search term:

site:daniweb.com +"samir ibrahim" +"Thread Solved"

If you know what forum/language you want to search:

site:daniweb.com +"samir ibrahim" +"Thread Solved" intitle:VB.NET

I got interesting results. Not bad at all.

it is either you know to much about daniweb or you work for google in your spare time. :D

if you think for a second that I will mark this thread as solved because you post the above, let me tell you nicely, YOU ARE WRONG :icon_lol:

samir_ibrahim 58 Junior Poster

> The feature is going to be put back

I will take your word for it, but I will not mark this thread as solved until you got it back :D

Keep the good work and good luck.

samir_ibrahim 58 Junior Poster

Hi cscgal

There is 3 reason why I want this link back.

Most of the time I post a code that exist in my application to help others, but sometimes, I get interested in a question such as a question how to check if a file exist on server using administrator credential, so I work 2 hours to made it and post it as answer.

and since I am very organized person, sometimes I cannot see my mouse on my desk :D I find it easier to find my solved thread and take that sample and put it in my application back when I need it :)

Second reason, I would like to know which post I solve, I had gone for 2 days for vacation, and come back to find 2 more solved thread added to my solved thread, I managed to know one of them, but could not find the other one.

third reason, I sometimes click on person profile who have a lot of solved thread in his count such as "sknake" or "adatapost" used to click on the solved thread link which you :icon_evil: removed :icon_lol: so I can take a peak on there solved thread and may found a useful code for me instead of searching.

Hope these reasons is enough, if not, I will get my lawyer to contact you :D

samir_ibrahim 58 Junior Poster

Hi

I am unable to list the threads that I solve any more.

Can someone show me where you hide this button :)

samir_ibrahim 58 Junior Poster

I know this way which let you choose the char you want to allow to be written in the textbox

'Textbox KeyPress
' Allow number 0-9 plus backspace, Del + Home + End will be accepted also
Dim ValidInputChar = "0123456789." + vbBack
If not ValidInputChar.Contains(e.KeyChar) then
    e.KeyChar=Nothing           
End If

'Textbox_Lostfocus
Dim TextboxToNumeric as Double = Val(TextBox4.Text)
TextBox4.Text = TextboxToNumeric.ToString("#,###.00")
samir_ibrahim 58 Junior Poster

Very nice trick

samir_ibrahim 58 Junior Poster

You are welcome

But you had spelled my name is wrong way, It take me a second to recognize that you are talking to me (lol)

Have a good day.

samir_ibrahim 58 Junior Poster
Dim ServerName = "pc_name"
Dim AdminUserName = "Administrator"
Dim DomainName = "domain_name"
Dim AdminPassword = "password"
' Initialize WMI
Dim objSWbemLocator As New WbemScripting.SWbemLocator
' Connect to remote PC


Dim objSWbemServices = objSWbemLocator.ConnectServer _
                       (ServerName, "root\cimv2", _
                       AdminUserName, AdminPassword, _
                       "MS_409", "ntlmdomain:" + DomainName)


Dim Drive,Path,FileName,Ext as String

Drive = chr(34) + "c:" + Chr(34)
Path = chr(34) + "\\newfolder\\" + chr(34)  
FileName = chr(34) + "test" + chr(34) 
Ext = chr(34) + "txt" + chr(34) 

 Dim oCIM_DataFile = objSWbemServices.ExecQuery _
                     ("select * from CIM_DataFile where drive = " & Drive _ 
                     & " and path = " & Path & " and filename = " & FileName _ 
                     & " and extension = " & Ext)

For Each obj In oCIM_DataFile
    ' If your program execution got here, then the file exist
    Debug.Print (obj.FileName)
Next
samir_ibrahim 58 Junior Poster

But, how do i actually get it to show?

Show what? the temperature result?

All I did is copy/paste your code, add the reference as I mention to you, and run the form, and it give me "not supported"

So I guess the code is working some some hardware.

Did you manage to run the code?

samir_ibrahim 58 Junior Poster

1- You had to add this line in top of the form
Imports System.Management

2- Add refrence for System.Management

samir_ibrahim 58 Junior Poster

Use the "New" Keyword

Dim frm As New TestInterop.InteropForm1
frm.Show

samir_ibrahim 58 Junior Poster

Hi

-I have a form where IsMdiContainer = True
-I add Split contaner which has 2 panel vertically (panel1 and panel2)
-In Panel1 I have buttons where every button should display a form in panel2

I want to display a form in the center of panel2
I had tried the below code and not working

frm_Login.TopLevel=False
frm_Login.Parent = Me.SplitContainer1.Panel2
Me.SplitContainer1.Panel2.Controls.Add(frm_Login)
frm_Login.StartPosition=FormStartPosition.CenterParent
''frm_Login.StartPosition=FormStartPosition.CenterScreen
frm_Login.Show

Should I do the math my self and assign Top and Left to the form?

TIA

samir_ibrahim 58 Junior Poster

You can try this (not tested deeply)

Dim SearchIn = Me.TextBox1.Text
Dim sb As StringBuilder = New StringBuilder(SearchIn)
Me.TextBox1.Text = sb.Replace(vbCrLf + vbCrLf, vbCrLf).ToString