Hi,
I Got an error: nullreferenceexception was unhandled by user code
while opening mysql connection through asp.net
for your information i am providing below the code from two files:
Code from connection.vb Imports Microsoft.VisualBasic
Imports MySql.Data.MySqlClient
Public Class Conn
Public adoconn As MySqlConnection
Function dcon()
adoconn = New MySqlConnection("server=localhost;database=TSdb;uid=root;pwd=123;AllowZeroDateTime=True;port=3306")
Return Nothing
End Function
End Class
Code from customermst.aspx.vb Imports MySql.Data.MySqlClient
Partial Public Class cstmaster
Inherits System.Web.UI.Page
Dim con As MySqlConnection
Dim cmd As MySqlCommand
Dim rdr As MySqlDataReader
Dim c1 As Conn = New Conn
Dim str As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub sumbit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles sumbit.Click
con = c1.adoconn
con.Open()
str = "insert into tblcst(nm,addr,city,mailid) values('" & txtcstnm.Text & "','" & txtadd.Text & "','" & txtcity.Text & "','" & txtmailid.Text & "')"
cmd = New MySqlCommand(str, con)
rdr = cmd.ExecuteReader()
rdr.Close()
con.Close()
End Sub
End Class
I am getting error (
nullreferenceexception was unhandled by user code ) while passing the code:
con.Open() Expecting your valuable reply in this regard to solve this issue.