How can I bind an entity Data Source to the results of a query - vb.net

I have a query that will go away an and find data
Dim HSNs As String = String.Join(",", ListOfHSNs.Cast(Of String)().ToArray())
Dim query As String = "SELECT VALUE O FROM v_BillData AS O WHERE O.HSNumber IN {'" & HSNs & "'}"
Dim hs As New ObjectQuery(Of v_BillData)(query, CType(Session("ObjectCon"), ObjectContext))
what I now wish to do is to use the results of this query to databind to a EntityDataSource
How can I do this?

You can try to use the Selecting EntityDataSource event like in the following example:
Protected Sub EntityDataSource1_Selecting(ByVal sender As Object, ByVal e As EntityDataSourceSelectingEventArgs)
Dim HSNs As String = String.Join(",", ListOfHSNs.Cast(Of String)().ToArray())
Dim query As String = "SELECT VALUE O FROM v_BillData AS O WHERE O.HSNumber IN {'" & HSNs & "'}"
Dim source As EntityDataSource = Nothing
source = TryCast(Me.Page.FindControl("EntityDataSource1"),EntityDataSource)
If (Not source Is Nothing) Then
source.EntitySetName = Nothing
source.CommandText = query
End If
End Sub
You should set EntitySetName to Nothing because it will throw an error if you have setup EntityDataSource before.

Related

Can't display Data in ComboBox Control of DropDownStyle (DropDownList)

I have the following requirement,
I have a ComboBox Control (DropDownList Style) which user has to select a given value, but can not edit. Then I save it to a Database Table, and it's working fine.
(dataRow("it_discount_profile") = Trim(cmbDisProfile.Text))
But when I try to show the same Data in the same ComboBox by retrieving it from the Database, it won't show.
(cmbDisProfile.Text = Trim(tempTb.Rows(0).Item("it_discount_profile")))
When I change the ComboBox to "DropDown Style", it works. But then the User can edit it.
Am I missing something here or is it like that? Any advice will be highly appreciated.
Im filling it in runtime using a procedure.
Private Sub filldisProfiles()
Dim sqlString As String = "SELECT discount_profile FROM tb_discount_profiles"
Dim tempTb As DataTable
Dim myTbClass As myClassTableActivities = New myClassTableActivities()
tempTb = myTbClass.myFunctionFetchTbData(sqlString)
cmbDisProfile.DataSource = tempTb
cmbDisProfile.DisplayMember = "discount_profile"
End Sub
Ok. Actually, Im trying to migrate one of my old project from VB to VB.Net. VB.Net is little new to me. Im using a self built classto reduce codes in other places. Im attaching the class below.
My actual requirement is to populate the combo box from a table. I like to do it in run time. I don't want users to edit it. If they want to add a new value, they have separate place (Form) for that. I think im doing it in a wrong way. If possible please give a sample code since I'm not familiar with the proposed method.
Public Function myFunctionFetchTbData(ByVal inputSqlString As String) As DataTable
Try
Dim SqlCmd As New SqlCommand(inputSqlString, conn)
Dim dataAdapter As New SqlDataAdapter(SqlCmd)
Dim fetchedDataSet As New DataSet
fetchedDataSet.Clear()
dataAdapter.Fill(fetchedDataSet)
Dim fetchedDataTable As DataTable = fetchedDataSet.Tables(0)
Return fetchedDataTable
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Function
' this sub will update a table
Public Sub MyMethodUpdateTable(ByVal sqlString As String, ByVal tbToUpdate As DataTable)
Dim SqlCmd As New SqlCommand(sqlString, conn)
Dim dataAdapter As New SqlDataAdapter(SqlCmd)
Dim objCommandBuilder As New SqlClient.SqlCommandBuilder(dataAdapter)
dataAdapter.Update(tbToUpdate)
End Sub
Public Function MyMethodfindRecord(ByVal strSearckKey As String, ByVal tableName As String, ByVal strColumnName As String) As Boolean
Try
Dim searchSql As String = "SELECT * FROM " & tableName & " WHERE " & strColumnName & "='" & strSearckKey & "'"
'Dim searchString As String = txtCategoryCode.Text
' searchOwnerCmd.Parameters.Clear()
' searchOwnerCmd.Parameters.AddWithValue("a", "%" & search & "%")
Dim tempTb As DataTable
Dim myTbClass As myClassTableActivities = New myClassTableActivities()
tempTb = myTbClass.myFunctionFetchTbData(searchSql)
If tempTb.Rows.Count = 0 Then
Return False
Else
Return True
End If
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Function
Public Function myFunctionFetchSearchTB(ByVal inputSqlString As String) As DataTable
Try
Dim SqlCmd As New SqlCommand(inputSqlString, conn)
Dim dataAdapter As New SqlDataAdapter(SqlCmd)
Dim fetchedDataSet As New DataSet
fetchedDataSet.Clear()
dataAdapter.Fill(fetchedDataSet)
Dim fetchedSearchTB As DataTable = fetchedDataSet.Tables(0)
Return fetchedSearchTB
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Function
OK. If I understood correctly, you have a problem in retrieving Data [String] from a Database Table into a ComboBox of DropDownStyle [DropDownList].
How do you fill/populate your ComboBox with Data From Database Table ?
In this link, Microsoft docs state, that:
Use the SelectedIndex property to programmatically determine the index
of the item selected by the user from the DropDownList control. The
index can then be used to retrieve the selected item from the Items
collection of the control.
In much more plain English
You can never SET ComboBox.Text Value while in DropDownList by code, which you already knew by testing your code, but you need to use DisplayMember and ValueMember or SelectedIndex.
ComboBox1.SelectedIndex = ComboBox1.FindStringExact(Trim(tempTb.Rows(0).Item("it_discount_profile")))
Please consider populating your ComboBox Control from Database Table using (Key,Value) Dictionary collection, here is an example
Thank you guys for all the advice's. The only way it can be done is the way u said. I thought of putting the working code and some points for the benefit of all.
proposed,
ComboBox1.SelectedIndex = comboBox1.FindStringExact(Trim(tempTb.Rows(0).Item("it_discount_profile")))"
does not work when u bind the datatable to the combobox. The values should be added to the combo box in run time if the above "SelectedIndex" method to work. The code to add items to the combobox is as follows(myClassTableActivities is a class defined by myself and its shown above),
Private Sub filldisProfiles()
Dim sqlString As String = "SELECT discount_profile FROM tb_discount_profiles"
Dim tempTb As DataTable
Dim myTbClass As myClassTableActivities = New myClassTableActivities()
tempTb = myTbClass.myFunctionFetchTbData(sqlString)
Dim i As Integer = 0
For i = 0 To tempTb.Rows.Count - 1
cmbDisProfile.Items.Add(Trim(tempTb.Rows(i).Item("discount_profile")))
Next
End Sub
After adding we can use the following code to display the data on combobox (DropDownList).
Private Sub txtItCode_TextChanged(sender As Object, e As EventArgs) Handles txtItCode.TextChanged
Try
Dim sqlString As String = "SELECT * FROM tb_items where it_code='" & Trim(txtItCode.Text) & "'"
Dim tempTb As DataTable
Dim myTbClass As myClassTableActivities = New myClassTableActivities()
tempTb = myTbClass.myFunctionFetchTbData(sqlString)
If Len(txtItCode.Text) < 4 Then
cmdAdd.Enabled = False
cmdDelete.Enabled = False
cmdSave.Enabled = False
Else
If tempTb.Rows.Count > 0 Then
With tempTb
txtItName.Text = Trim(tempTb.Rows(0).Item("it_name"))
cmbDisProfile.SelectedIndex = cmbDisProfile.FindStringExact(Trim(tempTb.Rows(0).Item("it_discount_profile")))
cmbProfitProfile.SelectedIndex = cmbProfitProfile.FindStringExact(Trim(tempTb.Rows(0).Item("it_profit_profile")))
cmbItCategory.SelectedIndex = cmbItCategory.FindStringExact(Trim(tempTb.Rows(0).Item("it_category")))
cmbFinanCategory.SelectedIndex = cmbFinanCategory.FindStringExact((tempTb.Rows(0).Item("it_finance_category")))
End With
cmdAdd.Enabled = False
cmdDelete.Enabled = True
cmdSave.Enabled = True
Else
cmdAdd.Enabled = True
cmdDelete.Enabled = False
cmdSave.Enabled = False
txtItName.Text = ""
Call fillItCategories()
Call fillProProfile()
Call filldisProfiles()
Call fillFinCat()
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try

Query in VB.net sometimes doesn't work

I have a functionality which saves the information from a webform to the database, which is working fine.
This is my code for save functionality in Onspec.aspx.vb page
Public Sub SaveClick(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsValid Then
litMessage.Text = ""
Exit Sub
End If
Try
Dim sName As String = ""
With EmployerCandidate
.employerid = Master.Employer.ID
.employeruserid = 0
Try
.CVID = DocId
Catch
End Try
.Name = uxName.Text
.SurName = uxSurname.Text
Try
.PostCode = uxPostcode.Text
Catch ex As Exception
End Try
.Email = uxEmail.Text
Try
.MobileNo = uxMobileNo.Text
Catch ex As Exception
End Try
.OnSpec = True
.OnSpecType = uxOnSpecCategory.SelectedItem.Text
.Source = uxSourceID.SelectedItem.Text
.LastEmployer = uxEmployer.Text
.LastJobTitle = uxJobtitle.Text
.Profile = uxProfile.Text.Trim
End With
' email()
ResetForm()
panForm.Visible = False
panUpload.Visible = True
uxSubmit.Visible = False
uxUpload.Visible = True
litMessage.Text = "Thank you for submitting your details! We'll be in touch when appropriate vacancy arises. <a href='#' onclick='parent.$.colorbox.close()'>Close</a>"
UploadPanel.Visible = False
Response.Redirect("onspec-complete.aspx?e=" & Master.Employer.ID)
Catch ex As Exception
litMessage.Text = Core.Helper.FancyMessage("Error as occurred - " & ex.Message.ToString, "ERROR")
End Try
End Sub
Now, I want to send emails along with saving the data in the database so I added the following lines of code before ResetForm().
Dim specmatch As DataRow = DB.GetRow("SELECT TOP 1 name,email,password FROM [user] usr JOIN employeruser empUsr ON usr.id = empUsr.userid WHERE empUsr.empusertype = 1 AND empUsr.employerid = #eid ", DB.SIP("eid", LocalHelper.UserEmployerID))
If my query returns a value then I want to send email by calling the email function.
If specmatch IsNot Nothing Then
email()
End If
But in this line of code the employerid value is sometimes empty. It can't pick the id therefore it is returning an empty row. And therefore it's not calling the email function.
This id is the same as
.employerid = Master.Employer.ID
But if I replace the LocalHelper.UserEmployerID with Master.Employer.ID the form gives an error:
Object reference not set to an instance of an object.
employerid is an integer value.
I have also tried to add the following lines of code in this page(Onspec.aspx.vb)
Public ReadOnly Property EmployerId() As Integer
Get
Return Master.Employer.ID
End Get
End Property
But I get the same error:
Object reference not set to an instance of an object.
The above lines of code does not make any difference.
So I replaced Master.Employer.ID with LocalHelper.UserEmployerID
Where in localhelper.vb file (under appcode folder) it is determining employerid from the website with following lines of code.
Public Shared Function UserEmployerID() As Integer
If HttpContext.Current.Items("lh_useremployerid") Is Nothing Then
If LocalHelper.UserTypeCode = "e" Then
HttpContext.Current.Items("lh_useremployerid") = Core.DB.GetInteger("SELECT employerid FROM employeruser WHERE userid = " & LocalHelper.UserID)
Else
HttpContext.Current.Items("lh_useremployerid") = 0
End If
End If
Return HttpContext.Current.Items("lh_useremployerid")
End Function
These lines of code has been used in many places and works perfectly fine. In this case as well, it was working fine last Friday and now it's not. There was no changes made.
This is my email function
Private Sub email()
Dim strCandidateName As String = uxName.Text.Trim & " " & uxSurname.Text.Trim
Dim strCandidateSurname As String = uxSurname.Text
Dim strCandidateEmail As String = uxEmail.Text.Trim
Dim strCandidatePhone As String = uxMobileNo.Text.Trim
Dim strCPass As String = "mpb123"
Dim strContactType As String = "Speculative Application has been submited on the category of " & uxOnSpecCategory.SelectedItem.Text
Dim strContactMessage As String = uxProfile.Text.Trim
'''''''''''''''''''variable
Dim qq As String = String.Format("Select top 1 name, email, password FROM [user] WHERE id in (Select userid FROM employeruser WHERE empusertype=1 and employerid= " & LocalHelper.UserEmployerID & ")")
Dim drow As DataRow = Core.DB.GetRow(qq)
Dim semail As String = drow.Item("email").ToString
Dim sname As String = drow.Item("name").ToString
Dim spass As String = drow.Item("password").ToString
'''''''''''''''''''variable
Dim Email As Core.Email
'New Onspec Candidate Email sent to EmployerUser who is assigned to receive onspec email
Email = New Core.Email
With Email
.ContentID = 99
.Replacement("ContactName", strCandidateName)
.Replacement("ContactEmail", strCandidateEmail)
.Replacement("ContactTelephone", strCandidatePhone)
.Replacement("ContactType", strContactType)
.Replacement("ContactMessage", strContactMessage)
.Replacement("AdminContactName", sname)
.Replacement("AdminContactEmail", semail)
.Replacement("SiteName", LocalHelper.AppSetting("sitename"))
Dim attachments As New Generic.List(Of String)
If EmployerCandidate.CVID > 0 Then
Dim doc As New Document(EmployerCandidate.CVID)
attachments.Add(doc.PathOnDisc)
End If
.Attachments = Join(attachments.ToArray(), ";")
.Send()
End With
End Sub
GetRow function is defined in my database.vb page like following which is also used in many other places.
Shared Function GetRow(ByVal selectQueryText As String, ByVal ParamArray params As SqlParameter()) As DataRow
Return GetRowFromDB(selectQueryText, CommandType.Text, params)
End Function
And
Shared Function GetRowFromDB(ByVal selectCommandText As String, ByVal selectCommandType As CommandType, ByVal ParamArray params As SqlParameter()) As DataRow
Dim conn As SqlConnection = Nothing
Try
conn = GetOpenSqlConnection()
Return GetRowFromDB(conn, selectCommandText, selectCommandType, params)
Finally
If conn IsNot Nothing Then conn.Dispose()
End Try
End Function
Please suggest ways on how I can organize my code so that it works all the time.

Deleting record from a datatable

I have the following code that works fine on the first execution but doesn't seem to find the previously deleted record when executed again. Any advice.Thanks
Private Sub TvContainer_NodeSelected(sender As Object, e As ComponentArt.Web.UI.TreeViewNodeEventArgs) Handles TvContainer.NodeSelected
Dim no As Integer
Dim dtpackunit As New DataTable
dtShipItem = Session("dsShipItem")
dtpackunit = Session("dsUnit")
no = TvContainer.SelectedNode.ID
Dim dt As DataTable = dtpackunit
Dim rows = dt.[Select]("No <> " & no)
For Each row In rows
row.Delete()
Next
gridbox.DataSource = dtpackunit
gridbox.DataBind()
gridship.DataSource = dtShipItem '.Select(filterExp, Nothing, Nothing)
gridship.DataBind()
End Sub

The select command property has not been initialized before calling 'Fill'

I am working on a Windows forms project that connects to a Microsoft Access database, reads the the file, does some math and then provides some basic statistics back. Right now I am teaching myself VB and I know the code below could be more efficient. However, right now I am just trying to make it functional.
The program filters the data it needs via sql, and there are several sql statements. I separated the code for each of the sql statements and into a subroutine so that I could call each one when the form loads and also when the user clicks a button to update. The program works fine on the form load, however, when you click the update button you get the following error on the 'odaCalls.Fill' in subroutine Count(): "The select command property has not been initialized before calling 'Fill'.
Any help is greatly appreciated. I have searched on google and tried the suggestions found there but have not found a fix.
Option Explicit On
Public Class Form1
'Count() Variables
Dim strSQL = "SELECT * FROM tblcallLog"
Dim strPath As String = "Provider=Microsoft.ACE.OLEDB.12.0 ;" _
& "Data Source=C:\callLogRev2_be.accdb"
Dim odaCalls As New OleDb.OleDbDataAdapter(strSQL, strPath)
Dim datCallCount As New DataTable
Dim intCount As Integer = 0
'LiveCalls() variables
Dim strSQLLive As String = "SELECT * FROM tblcallLog WHERE callLive=True"
Dim odaCallsLive As New OleDb.OleDbDataAdapter(strSQLLive, strPath)
Dim datCallLive As New DataTable
Dim intCallLiveCount As Integer = 0
Dim decCallLivePct As Decimal
'TransferCalls() variables
Dim strSQLTransfered As String = _
"SELECT * FROM tblcallLog WHERE callName LIKE '% transfer %' OR callName LIKE 'transfer%'"
Dim odaCallsTransfered As New OleDb.OleDbDataAdapter(strSQLTransfered, strPath)
Dim datCallTransfered As New DataTable
Dim intCallTransfered As Integer = 0
Dim decCallTranfered As Decimal
'SingleStaffCall() Variables
Dim strSQLSingleStaff As String = _
"SELECT * FROM tblcallLog WHERE callName LIKE '% single %' OR callName LIKE 'single%'"
Dim odaCallSingleStaff As New OleDb.OleDbDataAdapter(strSQLSingleStaff, strPath)
Dim datCallSingleStaff As New DataTable
Dim intCallSingleStaff As Integer = 0
Dim decCallSingleStaff As Decimal
'SingleStaffCallsLive() Variables
Dim strSQLSingleStaffLive As String = _
"SELECT * FROM tblcallLog WHERE callName LIKE '% single %' OR callName LIKE 'single%' AND callLive=True"
Dim odaCallSingleStaffLive As New OleDb.OleDbDataAdapter(strSQLSingleStaffLive, strPath)
Dim datCallSingleStaffLive As New DataTable
Dim intCallSingleStaffLive As Integer = 0
Dim decCallSingleStaffLive As Decimal
'CallToday() Variables
Dim strSQLToday As String = _
"SELECT * FROM tblcallLog WHERE startDate = date()"
Dim odaCallToday As New OleDb.OleDbDataAdapter(strSQLToday, strPath)
Dim datCallToday As New DataTable
Dim intCallToday As New Integer
'CallTodayLive() Variables
Dim strSQLTodayLiveCalls As String = _
"SELECT * FROM tblcallLog WHERE callLive=TRUE AND startDate = date()"
Dim odaCallTodayLive As New OleDb.OleDbDataAdapter(strSQLTodayLiveCalls, strPath)
Dim datCallTodayLive As New DataTable
Dim intCallTodayLive As New Integer
Dim decCallTodayLive As New Decimal
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Count()
LiveCalls()
TransferCalls()
SingleStaffCalls()
SingleStaffCallsLive()
CallToday()
CallTodayLive()
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
'Checks the database for updates when user pushes the update button on the static data tab.
Count()
LiveCalls()
TransferCalls()
SingleStaffCalls()
SingleStaffCallsLive()
CallToday()
CallTodayLive()
End Sub
Private Sub Count()
'database connect and call count
odaCalls.Fill(datCallCount)
odaCalls.Dispose()
intCount = datCallCount.Rows.Count
lblTotalCallsData.Text = intCount.ToString
lblTotalCallsData.Visible = True
End Sub
Private Sub LiveCalls()
'determine number of live calls
odaCallsLive.Fill(datCallLive)
odaCallsLive.Dispose()
intCallLiveCount = datCallLive.Rows.Count
lblcallsLiveData.Text = intCallLiveCount.ToString
lblcallsLiveData.Visible = True
decCallLivePct = intCallLiveCount / intCount
lblPctCallsLiveData.Text = decCallLivePct.ToString("P")
lblPctCallsLiveData.Visible = True
End Sub
Private Sub TransferCalls()
'determine the number of transfer calls
odaCallsTransfered.Fill(datCallTransfered)
odaCallsTransfered.Dispose()
intCallTransfered = datCallTransfered.Rows.Count
lblTotalTransferCallsData.Text = intCallTransfered.ToString
lblTotalTransferCallsData.Visible = True
decCallTranfered = intCallTransfered / intCount
lblPctTransferCallsData.Text = decCallTranfered.ToString("P")
lblPctTransferCallsData.Visible = True
End Sub
Private Sub SingleStaffCalls()
'determine the number of single staff calls and percentage of total
odaCallSingleStaff.Fill(datCallSingleStaff)
odaCallSingleStaff.Dispose()
intCallSingleStaff = datCallSingleStaff.Rows.Count
lblTotalSingleStaffCallData.Text = intCallSingleStaff.ToString
lblTotalSingleStaffCallData.Visible = True
decCallSingleStaff = intCallSingleStaff / intCount
lblPctSingleStaffCallsData.Text = decCallSingleStaff.ToString("P")
End Sub
Private Sub SingleStaffCallsLive()
'determine the percentage of single staff calls taken live
odaCallSingleStaffLive.Fill(datCallSingleStaffLive)
odaCallSingleStaffLive.Dispose()
intCallSingleStaffLive = datCallSingleStaffLive.Rows.Count
decCallSingleStaffLive = intCallSingleStaffLive / intCount
lblPctSingleStaffCallsLiveData.Visible = True
lblPctSingleStaffCallsLiveData.Text = decCallSingleStaffLive.ToString("P")
End Sub
Private Sub CallToday()
'determine values for todays date
odaCallToday.Fill(datCallToday)
odaCallToday.Dispose()
intCallToday = datCallToday.Rows.Count
lblTotalCallsTodayData.Text = intCallToday
lblTotalCallsTodayData.Visible = True
End Sub
Private Sub CallTodayLive()
'determine the number of live calls today
odaCallTodayLive.Fill(datCallTodayLive)
odaCallTodayLive.Dispose()
intCallTodayLive = datCallTodayLive.Rows.Count
lblCallsTodayLiveData.Text = intCallTodayLive.ToString
lblCallsTodayLiveData.Visible = True
'Statement to error correct so the database doesn't force the program to divide by zero
Try
decCallTodayLive = intCallTodayLive / intCallToday
Catch Exception As DivideByZeroException
lblPctCallsTodayLiveData.Text = "0.00%"
lblPctCallsTodayLiveData.Visible = True
Catch Exception As OverflowException
decCallTodayLive = 0
End Try
lblPctCallsTodayLiveData.Text = decCallTodayLive.ToString("P")
lblPctCallsTodayLiveData.Visible = True
End Sub
End Class
The problem is that you are disposing the dataadapters immediately after filling them.
This is why it works on form load, but not after. It would be better practice to create the and destroy the dataadapters in the methods where they are used instead of creating them on spec at the form level.

Object reference not set to an instance of an object

Can anyone help with the following code?
I'm trying to get data from the database colum to the datagridview...
I'm getting error over here "Dim sql_1 As String = "SELECT * FROM item where item_id = '" + DataGridView_stockout.CurrentCell.Value.ToString() + "'""
Private Sub DataGridView_stockout_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView_stockout.CellMouseClick
Dim i As Integer = Stock_checkDataSet1.Tables(0).Rows.Count > 0
Dim thiscur_stok As New System.Data.SqlClient.SqlConnection("Data Source=MBTHQ\SQLEXPRESS;Initial Catalog=stock_check;Integrated Security=True")
' Sql Query
Dim sql_1 As String = "SELECT * FROM item where item_id = '" + DataGridView_stockout.CurrentCell.Value.ToString() + "'"
' Create Data Adapter
Dim da_1 As New SqlDataAdapter(sql_1, thiscur_stok)
' Fill Dataset and Get Data Table
da_1.Fill(Stock_checkDataSet1, "item")
Dim dt_1 As DataTable = Stock_checkDataSet1.Tables("item")
If i >= DataGridView_stockout.Rows.Count Then
'MessageBox.Show("Sorry, DataGridView_stockout doesn't any row at index " & i.ToString())
Exit Sub
End If
If 1 >= Stock_checkDataSet1.Tables.Count Then
'MessageBox.Show("Sorry, Stock_checkDataSet1 doesn't any table at index 1")
Exit Sub
End If
If i >= Stock_checkDataSet1.Tables(1).Rows.Count Then
'MessageBox.Show("Sorry, Stock_checkDataSet1.Tables(1) doesn't any row at index " & i.ToString())
Exit Sub
End If
If Not Stock_checkDataSet1.Tables(1).Columns.Contains("os") Then
'MessageBox.Show("Sorry, Stock_checkDataSet1.Tables(1) doesn't any column named 'os'")
Exit Sub
End If
'DataGridView_stockout.Item("cs_stockout", i).Value = Stock_checkDataSet1.Tables(0).Rows(i).Item("os")
Dim ab As String = Stock_checkDataSet1.Tables(0).Rows(i)(0).ToString()
End Sub
I keep on getting the error saying "Object reference not set to an instance of an object"
I dont know where I'm going wrong.
Help really appreciated!!
Stock_checkDataSet1.Tables(1)
I think you need to use a 0 index.
Start the debugger and turn on break on exception, you'll see the exact point where the exception occurs then.