|
I am using datatable in my application to show the data in gridview.Now what I want is that when user enter a new line application should check the datatable.if the record exists then it should show a warning otherwise add a new row in datatable.
I am using the following code to check the datatable through loop.
Dim x As DataRow
For Each x In mydatatable.Rows
If x.Item(1).ToString = Me.TextBox1.Text Then
Me.Label1.Text = "Exist"
End If
Next
With the above code I am getting error 'Object reference not set to an instance of an object.' at the first row of the for loop
Ejaz
Ejaz
|
|
|
|
|
ejaz_pk wrote: If x.Item(1).ToString = Me.TextBox1.Text Then
I think this line is causing the issue. Does your datatable has column 1?
Mubashir
Software Architect
Storan Technologies Inc, USA
Every job is a self portrait of the person who did it.
|
|
|
|
|
Here is coding for the application
I am getting error message when click on button1_click event
Imports System.Data
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page
Dim MYDT As DataTable
Dim mydatatable As DataTable
Private Function CreateDataTable() As DataTable
mydatatable = New DataTable()
Dim myDataColumn As DataColumn
myDataColumn = New DataColumn()
myDataColumn.DataType = Type.GetType("System.String")
myDataColumn.ColumnName = "id"
myDataTable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn()
myDataColumn.DataType = Type.GetType("System.String")
myDataColumn.ColumnName = "username"
myDataTable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn()
myDataColumn.DataType = Type.GetType("System.String")
myDataColumn.ColumnName = "firstname"
myDataTable.Columns.Add(myDataColumn)
myDataColumn = New DataColumn()
myDataColumn.DataType = Type.GetType("System.String")
myDataColumn.ColumnName = "lastname"
myDataTable.Columns.Add(myDataColumn)
Return myDataTable
End Function
Private Sub AddDataToTable(ByVal username As String, ByVal firstname As String, ByVal lastname As String, ByVal myTable As DataTable)
Dim row As DataRow
row = myTable.NewRow()
row("id") = Guid.NewGuid().ToString()
row("username") = username
row("firstname") = firstname
row("lastname") = lastname
myTable.Rows.Add(row)
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
If Me.IsPostBack = False Then
MYDT = New Data.DataTable()
MYDT = CreateDataTable()
Session("myDatatable") = MYDT
Me.GridView1.DataSource = (CType(Session("myDatatable"), Data.DataTable)).DefaultView
Me.GridView1.DataBind()
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.TextBox1.Text.Trim() = "" Then
Me.Label1.Text = "You must fill a username."
Return
Else
Dim x As DataRow
For Each x In mydatatable.Rows
If x.Item(1).ToString = Me.TextBox1.Text Then
Me.Label1.Text = "Exist"
End If
Next
AddDataToTable(Me.TextBox1.Text.Trim(), Me.TextBox2.Text.Trim(), Me.TextBox3.Text.Trim(), CType(Session("myDatatable"), DataTable))
Me.GridView1.DataSource = CType(Session("myDatatable"), DataTable).DefaultView
Me.GridView1.DataBind()
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""
Me.TextBox3.Text = ""
Me.Label1.Text = ""
Me.TextBox1.Focus()
End If
End Sub
End Class
-- modified at 5:43 Wednesday 15th August, 2007
|
|
|
|
|
You have several issues here
1 - you're giving all your variables names that obsfucate your code. Give them real names
2 - you need to learn how to use the debugger, you should set a break point or two in your code, and examine your data source to see what's going wrong
3 - you have two datatables as members, called MYDT and myDataTable ( or something ). More bad naming
4 - SQL is what you use to filter a data source. What you're doing is not the right way to go about filtering data.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks Christian for reply. Actually this is my test code and not using in the application. This is my first test by using datatable in asp.net
|
|
|
|
|
hi all
i m having a class like
public class c1
end class
now what i m trying to do is
public class c1
'some code
public class c2
'some code
end class
end class
how can i use the class c2, at this movement the class c2 is not executing,
how can i execute it. i also tryed
i m having a class like
public class c1
end class
now what i m trying to do is
public class c1
public sub new()
private _c2 as new c1
end sub
'some code
public class c2
'some code
end class
end class
but this one generates an unexpected error that crashes the vb.net
can some one tell what is worng with it and how can i use this sub class.
the main class is a control, and the sub class is another control that i m trying to place on the main class's control( also contain some events that force the control to move on the main control )
thnx
help everyone
|
|
|
|
|
The questions is....
how you declared a private variable in that position?
A.E.K
|
|
|
|
|
can u describe it in more detail. i just can't understand what u r trying to say.
thnx
help everyone
|
|
|
|
|
eyes2007 wrote: public sub new()
private _c2 as new c1
end sub
'some code
You can't declare something as private when it's declared within a method ( which is what your constructor is ). You have to declare it outside the constructor for it to be a member, and for private/public to have meaning.
eyes2007 wrote: the main class is a control, and the sub class is another control that i m trying to place on the main class's control
This is a bad design. Place one control inside another, sure, but it makes no sense to declare them that way
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I make a program with Winsock control, and its running on my pc. But this program can't run on aother pc, with this message: "Component 'MSWINSCK.OCX' or one of its dependencies not correctly registered: a file is missing or invalid."
How to make any computer can run this program???
thanks,
[i'm beginner]
|
|
|
|
|
Seems likely that you need to install and register mswinsck.ocx
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hello
please help me how to set a combo box readonly so user couldnot write into combbox.
thanks.
|
|
|
|
|
I believe there's a property for the style of box, and one of those is dropdownlist, that means it's a list only, no typing allowed.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi dear i think here is your answer
http://www.codeproject.com/cs/miscctrl/ReadOnlyComboBox.asp
Salman Sheikh
|
|
|
|
|
I'm now developing a small antivirus as my personal tool to wipe out viruses. I then wanna have it to scan automatically the files and folders that Windows or users use, as it is in Norton AV (Enable Auto Protect), McAfee (On-Access Scan) and so on. But I can't find any code to do that. Can anyone help me on this?
Everything has its start. So, start something today; then you will be a step forward.
-- modified at 22:07 Tuesday 14th August, 2007
|
|
|
|
|
Do you honestly expect that a small program you write is going to do better than programs like AVG ? Even if you were not using VB6, I'd still doubt that.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I never expect my small program to be better than the professional AV. But I just wanna do something for myself, improve my knowledge for depth VB programming. In the other words, I do it for my personal use or others if they need, and for FUN programming.
Can you help me then? I just want a piece of code that get FILENAME or FOLDER NAME that windows is accessing.
|
|
|
|
|
You can't do it in VB6 code. You have to write a piece of code that hooks the file I/O API, using a technique called "DLL Code Injection". This code has to be written in C++ to support the exports required by the technique. You'll be interacting with the O/S at the kernel level, so I sure hope you know what you're doing.
|
|
|
|
|
Hello all,
I was given a control library and need to add it as a reference to my project. It was created as a dll using the .NET framework (which is the same one I am working with) but visual studio will not let me add it as a reference. I get the error message "not a valid assembly or COM component." I know this library works because I have seen it in action but I'm having no luck.
Sorry this is so vague but any ideas?
|
|
|
|
|
You can only add a reference to a .NET Managed-code DLL or a COM-based .DLL. Library DLL's don't get a reference. You have to P/Invoke the functions in these DLL's.
The other thing that may be stopping you is if the .DLL is forced to use a different version of the .NET Framework than 2.0. You cannot load two different versions of the .NET CLR into the same process.
|
|
|
|
|
This was, as I suspected, just bad code, and that was recognized by another pair of eyes. The problem in finding it, is that at run time it is legitimate code, just not what I intended. The call to 'GetDefaultFileExtensions' should not have had an argument. tg
'****************************************
I know that I get pretty dumb late in the day, so I hope someone can just point out the source my stupidity.
Below is partial code from a class. I'm accessing the 2 properties and getting truncated results for both. For discussion's sake I'll just describe 1 of them - 'DefaultFileExtension'. This property's ReadOnly method calls the 'GetDefaultFileExtensions' function which should return the value of a constant, which in this case is "*.pdf". Look at the 2 'MsgBox' items in the code. I put them there for debugging. The message box inside of the 'GetDefaultFileExtensions' function displays "*.pdf". The message box in the 'DefaultFileExtension. property get displays "*" as the returned value from 'GetDefaultFileExtensions'.
I've tried replacing the sReturn variable with the literal "*.pdf" and still get the same result. Also recompiled, and even rebooted.
I'm stumped and open to suggestions.
Thanks, Tom
'******************************************
Friend Class clsFileDefinitionStructure
Friend Enum fdFileType
PDF_ft
Image_ft
End Enum
Private Const mc_DefaultFiletypeDescription_PDF As String = "PDF files"
Private Const mc_DefaultFiletypeDescription_Image As String = "Image files"
Private Const mc_DefaultFileExtension_PDF As String = "*.pdf"
Private Const mc_DefaultFileExtension_Image As String = "*.gif;*.bmp;*.jpg;*.jpeg;*.tif;*.png;*.pcd;*.pcx"
Private m_FileType As fdFileType = fdFileType.PDF_ft
Friend ReadOnly Property DefaultFileExtension() As String
Get
MsgBox(GetDefaultFileExtensions(m_FileType))
Return GetDefaultFileExtensions(m_FileType)
End Get
End Property
Friend ReadOnly Property DefaultFileTypeDescription() As String
Get
Return GetDefaultFileTypeDescription(m_FileType)
End Get
End Property
Private Function GetDefaultFileExtensions() As String
Dim sReturn As String
Select Case m_FileType
Case fdFileType.Image_ft
sReturn = mc_DefaultFileExtension_Image
Case fdFileType.PDF_ft
sReturn = mc_DefaultFileExtension_PDF
Case Else
sReturn = "*.*"
End Select
MsgBox(sReturn)
Return sReturn
End Function
Private Function GetDefaultFileTypeDescription() As String
Dim sReturn As String
Select Case m_FileType
Case fdFileType.Image_ft
sReturn = mc_DefaultFiletypeDescription_Image
Case fdFileType.PDF_ft
sReturn = mc_DefaultFiletypeDescription_PDF
Case Else
sReturn = "All Files"
End Select
Return sReturn
End Function
End Class
-- modified at 9:14 Wednesday 15th August, 2007
Tom Garth
Developer
R. L. Nelson and Associates, Inc., Virginia
|
|
|
|
|
I have no idea why this is happening. The code doesn't show anything that would cause it.
I'd remove the MsgBox lines and just step through the code, line-by-line, using the debugger and watch the variables involved.
|
|
|
|
|
Hi Dave,
I had already used the debugger while working line by line. I added the message boxes to make it easier to try different variations.
The only thing the code shows is that I stupidly added the FileType Enum as an argument to a call that didn't ask for an argument. The result was explained to me by in a very elegant answer from Armin Zingler at:
http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.dotnet.languages.vb&mid=03cf9ea6-b81a-48fe-ad43-f1f48517dbdc[^]
I've copied his explanation here:
************************************************************
This is awesome... The thing is that
GetDefaultFileExtensions(m_FileType)
is short for
GetDefaultFileExtensions.Chars(m_FileType)
because Chars is the default property of a String, and because
GetDefaultFileExtensions does /not/ have arguments. As m_FileType is 0, this
is actually
GetDefaultFileExtensions.Chars(0)
So, you get the first char of the string, which is "*" only.
Armin
************************************************************
Cool huh?
Tom Garth
Developer
R. L. Nelson and Associates, Inc., Virginia
|
|
|
|
|
Oh my God! I was poking through that code for an hour and didn't see it! :->
|
|
|
|
|
Hello friends of the Forum
I go to their valuable help with the following problem
It is possible from net to automate Directory Activates.
Concretely I want to activate the directive one that this in
Configuration of User
Administrative insoles
System
And to enable the directive one
Alone to Execute applications of allowed windows
And to establish the list of programs EXE that the user can execute, I can them
to select of a list.
Example: winword.exe, excel.exe, etc.
My idea is that the user can make it from ASP.net
I wait their valuable help, and thank you for their time
|
|
|
|