Quantcast
Channel: VBForums - Database Development
Viewing all articles
Browse latest Browse all 2918

MyDatAdp.fill(MyDataTbl) invalid object name

$
0
0
I need help in this code

I just learning VB 2012 and I have copied a code from internet and I have modified it. I have created the sqlserver database and its table from VB 2012, everything is good except when I filling the table I had got this error reading the table " Invalid Object name 'Gastos' ". Here is the code:

I will appreciate your help in advance thank you


Imports System.Data
Imports System.Data.SqlClient
Public Class Form1

Private MyCn As New SqlConnection
Private MyDatAdp As New SqlDataAdapter
Private MyCmdBld As New SqlCommandBuilder
Private MyDataTbl As New DataTable
Private MyRowPosition As Integer = 0
Sub form_load(sender As Object, e As EventArgs) Handles MyBase.Load


MyCn.ConnectionString = "Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\MANNY\documents\visual studio 2012\projects\Expenses1\Expenses1\Expenses.mdf;Integrated Security=True"

MyCn.Open()


MyDatAdp = New SqlDataAdapter("Select* from Gastos", MyCn)
MyCmdBld = New SqlCommandBuilder(MyDatAdp)
MyDatAdp.Fill(MyDataTbl)

Dim MyDataRow As DataRow = MyDataTbl.Rows(0)
Dim strAccount As String
Dim strName As String
Dim strValue As String
Dim strDate As String


strAccount = MyDataRow("Account")
strName = MyDataRow("Name")
strValue = MyDataRow("Value")
strDate = MyDataRow("date")

txtAccount.Text = strAccount.ToString
txtName.Text = strName.ToString
txtValue.Text = strValue.ToString
txtDate.Text = strDate.ToString

End Sub


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

Dim MyNewRow As DataRow = MyDataTbl.NewRow()
MyDataTbl.Rows.Add(MyNewRow)
MyRowPosition = MyDataTbl.Rows.Count - 1
Me.showRecords()

End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click


MyRowPosition = 0
Me.showRecords()


End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

If MyDataTbl.Rows.Count > 0 Then
MyRowPosition = MyDataTbl.Rows.Count - 1
Me.showRecords()
End If

End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click


If MyRowPosition < (MyDataTbl.Rows.Count - 1) Then
MyRowPosition = MyRowPosition + 1
Me.showRecords()
End If
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click



If MyDataTbl.Rows.Count > 0 Then
MyRowPosition = MyDataTbl.Rows.Count - 1
Me.showRecords()
End If
End Sub

Private Sub showRecords()

If MyDataTbl.Rows.Count = 0 Then
txtAccount.Text = ""
txtName.Text = ""
txtValue.Text = ""
txtDate.Text = ""


Exit Sub
End If

txtAccount.Text = MyDataTbl.Rows(MyRowPosition)("Account").ToString
txtName.Text = MyDataTbl.Rows(MyRowPosition)("Name").ToString
txtValue.Text = MyDataTbl.Rows(MyRowPosition)("Value").ToString
txtDate.Text = MyDataTbl.Rows(MyRowPosition)("Date").ToString
End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
If MyDataTbl.Rows.Count <> 0 Then
MyDataTbl.Rows(MyRowPosition)("Account") = txtAccount.Text
MyDataTbl.Rows(MyRowPosition)("Name") = txtName.Text
MyDataTbl.Rows(MyRowPosition)("value") = txtValue.Text
MyDataTbl.Rows(MyRowPosition)("date") = txtDate.Text

MyDatAdp.Update(MyDataTbl)
End If
End Sub

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
If MyDataTbl.Rows.Count <> 0 Then
MyDataTbl.Rows(MyRowPosition).Delete()
MyDatAdp.Update(MyDataTbl)
MyRowPosition = 0
Me.showRecords()
End If
End Sub


End Class

Viewing all articles
Browse latest Browse all 2918

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>