Click here to Skip to main content
15,881,588 members
Home / Discussions / Web Development
   

Web Development

 
GeneralMessage Closed Pin
13-Jul-22 6:24
professionalKevin Marois13-Jul-22 6:24 
GeneralRe: .Net Framework Web API & Client - Empty JSON Pin
Richard Deeming13-Jul-22 6:55
mveRichard Deeming13-Jul-22 6:55 
GeneralRe: .Net Framework Web API & Client - Empty JSON Pin
Kevin Marois13-Jul-22 8:14
professionalKevin Marois13-Jul-22 8:14 
QuestionVisual Studio 2022 vs Visual Studio Code for Angular development Pin
Danpeking9-Jun-22 23:20
Danpeking9-Jun-22 23:20 
AnswerRe: Visual Studio 2022 vs Visual Studio Code for Angular development Pin
thatraja2-Aug-22 1:48
professionalthatraja2-Aug-22 1:48 
AnswerRe: Visual Studio 2022 vs Visual Studio Code for Angular development Pin
Jeremy Falcon15-Dec-22 13:14
professionalJeremy Falcon15-Dec-22 13:14 
AnswerRe: Visual Studio 2022 vs Visual Studio Code for Angular development Pin
Nitin S11-Apr-23 18:14
professionalNitin S11-Apr-23 18:14 
QuestionSearch Function Pin
Yhanzoe Adigue6-Jun-22 16:28
Yhanzoe Adigue6-Jun-22 16:28 
Good Day!

Asking for Help about Asp.Net (vb code) Search Error.

The Scenario is When I search for data, I get it. Then when I search again, I get the error "System.NullReferenceException: 'Object reference not set to an instance of an object.'"

How to fix this error?

Thanks and advance.

Here's my code below:

Dim strKeyWord As String
Dim str As String
Dim cmd As New MySqlCommand
Dim da As New MySqlDataAdapter
Dim ds As New DataSet
Dim objConn As New MySqlConnection

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
strKeyWord = Me.txtSEARCH.Text
End Sub


Sub BindData()

Try

strConnString = "Host=;userid=;password=;database=;port=3306;"
str = "SELECT * FROM DataDB WHERE (sc_last_name Like '%" & strKeyWord & "%')"
objConn.ConnectionString = strConnString

With cmd
.Connection = objConn
.CommandText = str
.CommandType = CommandType.Text
End With

da.SelectCommand = cmd <---- The error is here when I search again Error: 'Object reference not set to an instance of an object.'
da.Fill(ds)

myGridView.DataSource = ds
myGridView.DataBind()

da = Nothing
objConn.Close()
objConn = Nothing
cmd.Dispose()

Catch ex As Exception
MsgBox(ex.Message)
End Try


End Sub

Sub myGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
Dim lblID As Label = CType(e.Row.FindControl("lblID"), Label)

If Not IsNothing(lblID) Then
lblID.Text = e.Row.DataItem("ID")
End If


Dim lblLN As Label = CType(e.Row.FindControl("lbLN"), Label)

If Not IsNothing(lblLN) Then
lblLN.Text = e.Row.DataItem("sc_last_name")
End If


Dim lblFN As Label = CType(e.Row.FindControl("lblFN"), Label)

If Not IsNothing(lblFN) Then
lblFN.Text = e.Row.DataItem("sc_first_name")
End If


Dim lblBDAY As Label = CType(e.Row.FindControl("lblBDAY"), Label)

If Not IsNothing(lblBDAY) Then
lblBDAY.Text = e.Row.DataItem("sc_dob")

End If

End Sub

Sub ShowPageCommand(ByVal s As Object, ByVal e As GridViewPageEventArgs)

myGridView.PageIndex = e.NewPageIndex
BindData()

End Sub

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

BindData()

End Sub



modified 7-Jun-22 6:59am.

AnswerRe: Search Function Pin
Pete O'Hanlon6-Jun-22 20:41
mvePete O'Hanlon6-Jun-22 20:41 
QuestionI'm trying to interact with a select element with selenium Pin
lucas lima 202229-May-22 13:25
lucas lima 202229-May-22 13:25 
AnswerRe: I'm trying to interact with a select element with selenium Pin
behruz1230-Jul-22 19:40
behruz1230-Jul-22 19:40 
QuestionNew MVC5 project, Bootstrap update, Fail Pin
#realJSOP26-May-22 4:41
mve#realJSOP26-May-22 4:41 
AnswerRe: New MVC5 project, Bootstrap update, Fail Pin
Richard Deeming26-May-22 21:41
mveRichard Deeming26-May-22 21:41 
AnswerRe: New MVC5 project, Bootstrap update, Fail Pin
Matthew Dennis27-May-22 4:18
sysadminMatthew Dennis27-May-22 4:18 
GeneralRe: New MVC5 project, Bootstrap update, Fail Pin
#realJSOP27-May-22 10:12
mve#realJSOP27-May-22 10:12 
QuestionIMAP and SMTP Server Pin
Aashna Khanna24-May-22 21:42
professionalAashna Khanna24-May-22 21:42 
AnswerRe: IMAP and SMTP Server Pin
Richard MacCutchan24-May-22 22:01
mveRichard MacCutchan24-May-22 22:01 
QuestionMVC5 Project Template Pin
#realJSOP13-May-22 0:06
mve#realJSOP13-May-22 0:06 
QuestionHow to send Email From Multiple SMTP In One shot. Pin
Ramendra Kumar Sinha11-May-22 18:52
Ramendra Kumar Sinha11-May-22 18:52 
AnswerRe: How to send Email From Multiple SMTP In One shot. Pin
Richard Deeming11-May-22 21:41
mveRichard Deeming11-May-22 21:41 
QuestionFont colour and background colour combinations hard to read Pin
Ross_Petersen2-May-22 22:24
professionalRoss_Petersen2-May-22 22:24 
AnswerRe: Font colour and background colour combinations hard to read Pin
Member 150787164-Jul-22 16:00
Member 150787164-Jul-22 16:00 
Questionhow do I get total quantity from this code Pin
wixily jnr28-Apr-22 13:26
wixily jnr28-Apr-22 13:26 
AnswerRe: how do I get total quantity from this code Pin
Richard MacCutchan28-Apr-22 21:32
mveRichard MacCutchan28-Apr-22 21:32 
GeneralRe: how do I get total quantity from this code Pin
wixily jnr29-Apr-22 8:17
wixily jnr29-Apr-22 8:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.