|
I'm getting an error that says:
nullreferenceexception was unhandled by user code
This is my Code:
Protected Sub GrdSorter(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
Dim dt As DataTable = TryCast(ViewState("grdNurseVisits"), DataTable)
Dim dvGridDataView As DataView = dt.DefaultView
Dim strSortOrder As String = ""
If ViewState("SortOrder") Is Nothing Then
ViewState("SortOrder") = "asc"
End If
If ViewState("SortOrder").ToString() = "asc" Then
ViewState("SortOrder") = "desc"
strSortOrder = "desc"
ElseIf ViewState("SortOrder").ToString() = "desc" Then
ViewState("SortOrder") = "asc"
strSortOrder = "asc"
End If
dvGridDataView.Sort = Convert.ToString(e.SortExpression) & " " & strSortOrder
dt = dvGridDataView.ToTable()
grdNurseVisits.DataSource = dt
grdNurseVisits.DataBind()
End Sub
I got the code from this site and there is step I didn't put in because I don't know the correct code.
this is the step:
Populate the ViewState with the datasource of the gridview in the If Not Page.IsPostBack
I don't know how to write that step in vb code
Could some one please let me know how to get this code to work...
|
|
|
|
|
Go to the place where you got the code and ask there.
Veni, vidi, abiit domum
|
|
|
|
|
|
Member 10386526 wrote: Thanks for nothing Think about your issue: you have downloaded some code from somewhere on the internet, without giving us any idea where it came from. There is a part that requires additional code which you expect us to understand, even though we have no idea what the code is based on. You have not explained which line the error occurred on, but you expect us to figure out why it doesn't work.
Veni, vidi, abiit domum
|
|
|
|
|
You have been on the site for a week, 7 days, and post a section of code saying you have an error, but don't know how to solve it.
Someone suggests you go to where you got the code from and ask there.
Assuming your 'this site' means CodeProject, then, was the code part of an article or what?
Did you ask the author of the code for help?
Member 10386526 wrote:
Thanks for nothing
Not a good way to start a relationship... we are VOLUNTEERS, not PAID STAFF.
|
|
|
|
|
I have a excel file that requires that data from a cell to be sent to another program. Instead of manually copying and pasting, is it possible to use VB to "tab" to an open window in another program (window is always named: "Message - New"), and to paste the data into.
Thanks!
Roy
|
|
|
|
|
|
 Here is a simplified VBA example that may be of help to you. The big issue is getting a handle to the window into which you want to paste.
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function FindWindowByCaption Lib "user32" _
Alias "FindWindowA" _
(ByVal thismustbezero As Long, _
ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" _
Alias "FindWindowExA" _
(ByVal parentHandle As Long, _
ByVal childAfter As Long, _
ByVal lclassName As String, _
ByVal windowTitle As String) As Long
Private Declare Function SendMessage Lib "user32.dll" _
Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Const WM_Paste As Long = &H302
Sub Test()
Dim res As Double
res = Shell("notepad.exe", vbNormalFocus)
Dim hWndNotepad As Long
hWndNotepad = FindWindowByCaption(0, "Untitled - Notepad")
Dim hwndEdit As Long
hwndEdit = FindWindowEx(hWndNotepad, 0, "Edit", "")
Range("Sheet1!A1").Formula = "This was copied from my excel spreadsheet"
Range("Sheet1!A1").Copy
Dim res2 As Long
res2 = SendMessage(hwndEdit, WM_Paste, 0, 0)
End Sub The Spy++ program included in the full version of Visual Studio is quite helpful for determining the class name of a window.
modified 14-Nov-13 22:48pm.
|
|
|
|
|
Works beautifully!!!! I've been trying everything and was resorting to using SendKeys, not pretty... I may have a small follow up question, but this is great! Thank you!
|
|
|
|
|
You are welcome.
You may want to read this[^] article if you have any problems getting the handle to your external application's window. I hate to enumerate windows, but many times it is the only way.
|
|
|
|
|
Dear Friends,
im using MS excel2003 VBA I created code to pull the data from one sheet to another sheet in same workbook using queries. But im getting error on ODBC Connection.
"" [Microsoft][ODBC Driver Manager] Data source name not found and no Default driver specified""
How to fix this error?????
|
|
|
|
|
It probably means you are missing a library component. However, your question is not clear, please show what your code is doing.
Veni, vidi, abiit domum
|
|
|
|
|
This error is commonly shown if you have no ODBC driver installed, or the installed version does not match the version you are referring in your code.
Or the data source can't be found, maybe a typo?
|
|
|
|
|
Hi,
I connected MySQL Database installed in Windows PC through network (Coded in VB.NET).
But one of my clients wants to install MySQL in Linux PC where the client PCs' OS are windows. He has the network installed.
My question is to do the above in VB.NET what should be
1. the process(how to),
2. connection string,
3. port #,
4. Firewall settings for both windows and Linux OS
and
5. others (if any).
I cannot test it right now as I do not have Linux installed anywhere. Is it just like the procedure in which I connected MySQL database installed in Windows PC? I used MySQL connector.NET to connect. If I want to connect Linux PC, what should I use? MySQL Connector/NET or MySQL Connector/ODBC ?
modified 13-Nov-13 9:29am.
|
|
|
|
|
1 and 2) How to do what?? Connect to the MySQL database in your code?? The exact same way you're doing it now. There are no changes as the connection to the database is completely O/S agnostic.
3) That is determined by the person installing the MySQL server on the Linux box. If the defulat ports are used, you don't have to change anything in your code.
4) This is not up to your code or you at all. This is left up to the admins at your customers site. If they want to run their own Linux server, they also have to support the infrastructure to allow clients to connect to it.
If you're the admin, well, you have a lot of stuff to learn about TCP/IP networks and firewalls that you're not going to get from a couple of forum posts. You will have to consult the MySQL documentation for the ports to open on the servers and clients firewalls.
Biplob Singha Shee wrote: Is it just like the procedure in which I connected MySQL database installed in
Windows PC? I used MySQL connector.NET to connect. If I want to connect Linux
PC, what should I use? MySQL Connector/NET or MySQL Connector/ODBC ?
Again, you don't change anything in your code. The connection to the database does not care about what O/S the server is running. What you're talking about is the provider that sits between your code and the server. This will not change because the server is different. What you use is dependent on your code and client environment, not the servers.
|
|
|
|
|
Hi Dave,
Thank you very very much for your quick reply. It really help me a lot.
Since I cannot test it because of non availability of Linux installation in any one of my PCs, so if I get any problem while testing it, I will definitely get back to you.
Thanks again,
Regards,
Biplob
|
|
|
|
|
If you want to test that, you can setup a Virtual Machine running on Linux. For the creation of Virtual Machines, you may use VirtualBox or (I prefer that) VMWare. Many Linux distributions contain a MySQL database.
And then you'll see that Dave is right: you do not need to change anything in your code.
|
|
|
|
|
anyone can help me to develop voting system based on image steganography? please
for my final year project.
|
|
|
|
|
fizie89 wrote: for my final year project. Which suggests that you are expected to do the work.
Veni, vidi, abiit domum
|
|
|
|
|
fizie89 wrote: anyone can help me
Sure
First search the articles here and read through them.
Then search Google for tutorials and examples on the subject. Work through the tutorials.
When you get a specific problem then ask here for support following the guidelines for forum questions.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Dear Sir,
I am facing still the problem regarding the editbuttoncolumn
when i click on the edit button and modify the record the control goes to "Created successfully, not updated the record just insert the new record with modifying field.
Regards
Anand.
|
|
|
|
|
If this relates to a previous question then please provide the details, or at least a link to that question.
Veni, vidi, abiit domum
|
|
|
|
|
|
 Dear Sir,
First of all,Thank you so much for your kind endevour to make the code right, it's working when i click on the edit button the selected record shows in the text box and clicking on the delete button it' working properly, but one thing is here , I change my code as you send to me but when I update the record and click on save button , the new record is added with update text box not updated the existing record, I am sending following my save button click event,
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
If validateform() Then
If id IsNot Nothing Then
Dim result As Boolean = lbll.updatelorry(txtLcode.Text.Trim(), txtLno.Text.Trim(), txtDname.Text.Trim())
If result = True Then
ClearText()
bindgrid()
id = Nothing
MessageBox.Show("Update Successfully")
End If
Else
Dim result As Boolean = lbll.insertlorry(txtLcode.Text.Trim(), txtLno.Text.Trim(), txtDname.Text.Trim())
If result = True Then
ClearText()
bindgrid()
MessageBox.Show("Created Successfully")
End If
End If
End If
End Sub
I have changed the "idstring" to id" which is used by you in my whole coding.one thing is there that in save button click event I have written that (if id isNoting) then proceed the update command. At this stage I already added the code "if id =0" cause he editbutton.index is 0, but it's not working throw message i.e
The method or operation is not implemented.
where as I am using the Function update.which is below
Public Function updatelorry(ByVal pkId As Integer, ByVal Lcode As String, ByVal Lno As String, ByVal Dname As String) As Boolean
Try
Dim param As SqlParameter() = New SqlParameter(3) {}
param(0) = New SqlParameter("@pkid", pkId)
param(1) = New SqlParameter("@lcode", Lcode)
param(2) = New SqlParameter("@lno", Lno)
param(3) = New SqlParameter("@dname", Dname)
SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.StoredProcedure, "updatelorry", param)
Return True
Catch
Throw
End Try
End Function
also it makes automatic another update function where the message throws which is below
Function updatelorry(ByVal p1 As String, ByVal p2 As String, ByVal p3 As String) As Boolean
Throw New NotImplementedException--error shows here
End Function
when i use in save button click event that
if id=editbutton.index then the same message throw.
Please suggest me what to do at this stage to make the update procedure active.
also if i use comment in the automatic created function then it shows another error is that
"Argument not specified for parameter 'Dname' of 'Public Function updatelorry(pkId As Integer, Lcode As String, Lno As String, Dname As String) As Boolean'.at save button click event
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
If validateform() Then
'If id IsNot Nothing Then
If id = editbutton.Index Then
Dim result As Boolean = lbll.updatelorry(txtLcode.Text.Trim(), txtLno.Text.Trim(), txtDname.Text.Trim())--Error Shows here
If result = True Then
ClearText()
bindgrid()
id = Nothing
MessageBox.Show("Update Successfully")
End If
Else
Dim result As Boolean = lbll.insertlorry(txtLcode.Text.Trim(), txtLno.Text.Trim(), txtDname.Text.Trim())
If result = True Then
ClearText()
bindgrid()
MessageBox.Show("Created Successfully")
End If
End If
End If
End Sub
the stored procedure od update command is
ALTER PROCEDURE [dbo].[updatelorry]
@lcode varchar(50),
@lno varchar(50),
@dname varchar(50),
@pkId int
AS
BEGIN
update lorrymaster set LCode=@lcode,Lno=@lno,Dname=@dname
where pkid=@pkId
select @pkId
END
Also the lorrymaster table structure is
CREATE TABLE [dbo].[lorrymaster](
[pkid] [int] IDENTITY(1,1) NOT NULL,
[lcode] [varchar](50) NULL,
[lno] [varchar](50) NULL,
[dname] [varchar](50) NULL,
[createdate] [smalldatetime] NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
|
|
|
|
|
Just some suggestions and observations. You may want to look at this tip[^] I use 1 proc to do both jobs so the UI/BL does not give a rats whether the record is new or not.
Try using CamelCase in your naming convention.
Try naming you ID field more sensibly, I recommend TableNameID so LorryMasterID
Try naming your fields better, you are not restricted by length dname => DriverName
Beyond the tip linked to I now return the RECORD just inserted/updated by the stored proc. This requires a gettable type call to the database instead of executescalar but you get the ID value back to you client (This may be the root cause of your current problem)
Beyond the above extension of a tip I would recommend building views to support any FK fields so the insert/update should return the VIEW of the LorryMaseter record just inserted/updated.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|