| | |
Datagrid Problem!!!!!!!
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2007
Posts: 23
Reputation:
Solved Threads: 0
I have inserted searching through passing parameter likewise. In search form there is only one textbox to pass the value. But there are three field names which are associated with that text box.
For example: I have searched by passing phone number
But there three field name tel1, tel2 and tel3 which which are called when the phone number is passed. my code is as follows. my frontend is vb.net and my backend is ms access.
In this snippet I have faced one problem. It shows one build error at
which says
And when I run this program it executes until I pass the values present in the field , but when i pass the values not present in the fields then the msg box is shown as mentioned the program...but the problem persists when I click the ok button of msg box or try to stop debugging.
It shows the error at
which shows
showing error.
I m a beginner of VB.net. so please help me what type of error is this and how can I solve this problem. please provide me with appropriate code to resolve the problem.
Anticipating the help.
Regards
Kshiteesh
For example: I have searched by passing phone number
But there three field name tel1, tel2 and tel3 which which are called when the phone number is passed. my code is as follows. my frontend is vb.net and my backend is ms access.
vb.net Syntax (Toggle Plain Text)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click [inlinecode] Db1DataSet1.Clear() Dim conStr As String = "Provider=Microsoft.JET.OLEDB.4.0;data source=K:\Database\db1.mdb" Dim con As OleDb.OleDbConnection = New OleDb.OleDbConnection(conStr) Dim S As String Dim datagrid1 As New DataGrid Dim tmp As New ADODB.Recordset tmp.Open("add1", conStr, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic) If TextBox1.Text = tmp.Fields("tel1").Value Then S = "select * from add1 where tel1='" & TextBox1.Text & "'" ElseIf TextBox1.Text = tmp.Fields("tel2").Value Then S = "select * from add1 where tel2='" & TextBox1.Text & "'" ElseIf TextBox1.Text = tmp.Fields("tel3").Value Then S = "Select * from add1 where tel3='" & TextBox1.Text & "'" ElseIf Not (tmp.EOF = True And tmp.BOF = True) Then : MsgBox("no record found") End If Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(S, con) da.Fill(Db1DataSet1, "add1") datagrid1.DataSource = Db1DataSet1.DefaultViewManager [/inlinecode] End Sub
In this snippet I have faced one problem. It shows one build error at
VB.NET Syntax (Toggle Plain Text)
OleDb.OleDbDataAdapter(S, con)
which says
VB.NET Syntax (Toggle Plain Text)
Variable 'S' is used before it has been assigned a value. A null reference exception could result at runtime.
And when I run this program it executes until I pass the values present in the field , but when i pass the values not present in the fields then the msg box is shown as mentioned the program...but the problem persists when I click the ok button of msg box or try to stop debugging.
It shows the error at
VB.NET Syntax (Toggle Plain Text)
da.Fill(Db1DataSet1, "add1")
which shows
VB.NET Syntax (Toggle Plain Text)
OledbException was unhandled
showing
VB.NET Syntax (Toggle Plain Text)
Command text was not set for the command object.
I m a beginner of VB.net. so please help me what type of error is this and how can I solve this problem. please provide me with appropriate code to resolve the problem.
Anticipating the help.
Regards
Kshiteesh
Hi Kshiteesh,
few points what i have noted here...:
1. Before Creating the DataAdapter, u are not checking if "S" is blank or not.. the error which u have may be the same..
or else in ur If condition if nothing found, then exit sub..
2. Use a new Dataset. Check this:
REgards
Veena
few points what i have noted here...:
1. Before Creating the DataAdapter, u are not checking if "S" is blank or not.. the error which u have may be the same..
or else in ur If condition if nothing found, then exit sub..
2. Use a new Dataset. Check this:
Dim ds AsNew DataSet da.Fill(ds, "add1") DataGrid1.DataSource = ds.DefaultViewManager
REgards
Veena
Last edited by QVeen72; Aug 9th, 2007 at 7:25 am.
![]() |
Similar Threads
- Need help on export asp.net table to excel (ASP.NET)
- Need help to finish datagrid problem (VB.NET)
- error on page!! Cannot solve!!Help (ASP.NET)
- SOS - datagrid problem (ASP.NET)
- How to do input validation when i am inserting new record into a datagrid ? (VB.NET)
- is this possible? (C#)
Other Threads in the VB.NET Forum
- Previous Thread: Using RecordsAffected as a parameter in an IF-THEN-ELSE statement
- Next Thread: to include dropdownlist,in datagrid....
Views: 2105 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2008 2008 access add advanced application array basic beginner browser button buttons center class click client code combo convert cpu cuesent data database datagrid datagridview datetimepicker design designer dissertation dissertations dissertationtopic eclipse employees excel exists forms function html images lib listview map mobile module msaccess mysql net number open page pan pdf picturebox picturebox2 port position print printing printpreview problem refresh regex reuse richtextbox right-to-left save search serial settings socket sorting sqldatbase sqlserver storedprocedure studio textbox timer timespan transparency txttoxmlconverter usercontol vb vb.net vb2008 vba vbnet vista visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web webbrowser winsock wpf wrapingcode xml year





