D
dennist
I'm unable to insert a new row because of the following
error message.
type = system.data.oledb.oledbexception
message = parameter?_3 has no default value.
First, I've gotten this far thanks mostly to Kevin Yu.
So I have confidence in the rest of the code. I'll put
the relevant code at the end. I've checked help, several
books and msdn for specific information on translating
microsoft access types to ado.net insert statements,
without getting any help.
One book had an example with a boolean, integer and
string types, so I'm fairly confident about those. Here
is an example of one of my parameer statements:
da.InsertCommand.Parameters.Add("@Issuer",
OleDb.OleDbType.Integer, 0, "Issuer")
Nowhere in the literature did I find what number to put
after the type. Especially after the memo type, or what
the number even stands for. In ado.net core reference
these numbers aren't even put in. However the example in
the other book worked, so I guess this syntax is also
valid.
The parameter 3 is topic issuer, which is an integer. You
can see in the code below my message box statement. This
verified that the number was okay and correct. I'm
assuming the list is 0 based, and issuer is actually the
fourth field. I didn't include the autoincrementing ID.
Another mystery is why intellisense insists the third
field is _Text. Nowhere in the access design mode is
this field begun with an underscore or a space. Might it
be related to its being a memo field?
Anyway, here is the relevant code:
Public Function NewTopic(frm as frmTopicFromStart) As
Boolean
NewTopic = False
'Dim cn As New OleDbConnection(gstrConn)
Try
cn.Open()
Catch er As Exception
MessageBox.Show("Type = " &
er.GetType.ToString & vbCr & "Message = " & er.Message)
End Try
'Dim da As OleDbDataAdapter = New OleDbDataAdapter
'Dim ds As New DataSet
'ds.DataSetName = "ds1"
'cn.Open()
'da.FillSchema(ds, SchemaType.Source, "Topics")
''cn.Close()
'ds.WriteXmlSchema("H:\HasbaraNET\ado.net
tests\CodeUpdate\ds.xsd")
Dim cmd As New OleDbCommand("SELECT * FROM
Topics", cn)
Dim da As OleDbDataAdapter = New OleDbDataAdapter
da.SelectCommand = cmd
' Fill the DataSet
Dim ds As DataSet = New DataSet
ds.DataSetName = "ds1"
'da.FillSchema(ds, SchemaType.Source, "Topics")
'ds.WriteXmlSchema("H:\HasbaraNET\ado.net
tests\TFSNet2\ds.xsd")
'da.Fill(ds, "Topics")
Dim dsA As New ds1
da.Fill(dsA, "Topics")
Dim tblTopics As ds1.TopicsDataTable = dsA.Tables
(0)
Dim rowTopics As ds1.TopicsRow
''Dim dr As DataRow
'Dim iRow As Integer
'iRow = dsA.Tables(0).Rows.Count - 1
'rowTopics = dsA.Tables(0).Rows(iRow)
'MsgBox(rowTopics.Issuer.ToString)
'isn't working because no rows
rowTopics = tblTopics.NewTopicsRow
rowTopics.ParentID = CInt(frm.txtParentID.Text)
rowTopics.Title = frm.txtTopicTitle.Text
rowTopics._Text = frm.txtTextGeneral.Text
rowTopics.Issuer =
frm.cboTopicIssuers.SelectedValue
MsgBox(rowTopics.Issuer.ToString)
rowTopics.BeginText = 0
rowTopics.Length = frm.txtTextGeneral.TextLength
rowTopics.PointOfView = frm.cboPOV.SelectedValue
rowTopics.PermissionID = CInt
(frm.txtPermission.Text)
rowTopics.Publisher =
frm.cboPublications.SelectedValue
rowTopics.CreateDate = Now
rowTopics.ChangeDate = Now
rowTopics.Active = True
'rowTopics.PermissionID = 6
MsgBox(rowTopics._Text.GetType.ToString())
'rowTopics.ID = 11
'rowTopics.ID = Integer.MaxValue
tblTopics.AddTopicsRow(rowTopics)
'da.InsertCommand = New OleDb.OleDbCommand
("INSERT INTO Topics
(ID,Topics,CreateDate,ChangeDate,Active) values
(?,?,?,?,?)", cn)
da.InsertCommand = New OleDb.OleDbCommand("INSERT
INTO Topics
(ParentID,Title,_Text,Issuer,BeginText,Length,PointOfView,
PermissionID,Publisher,CreateDate,ChangeDate,Active)
values (?,?,?,?,?,?,?,?,?,?,?,?)", cn)
'INSERT INTO [Order Details] (OrderID, ProductID,
Quantity, UnitPrice) VALUES (?, ?, ?, ?)
'Dim cmdGetIdentity As New OleDbCommand("SELECT
@@IDENTITY", cn)
AddHandler da.RowUpdated, AddressOf OnRowUpDated
'Try
' da.InsertCommand.Parameters.Add("@ID",
OleDb.OleDbType.Integer, 4, "ID")
'Catch er As Exception
' MessageBox.Show("Type = " &
er.GetType.ToString & vbCr & "Message = " & er.Message)
'End Try
da.InsertCommand.Parameters.Add("@ParentID",
OleDb.OleDbType.Integer, 0, "ParentID")
da.InsertCommand.Parameters.Add("@Title",
OleDb.OleDbType.VarChar, 255, "Title")
da.InsertCommand.Parameters.Add("@_Text",
OleDb.OleDbType.LongVarChar, 0, "_Text")
da.InsertCommand.Parameters.Add("@Issuer",
OleDb.OleDbType.Integer, 0, "Issuer")
da.InsertCommand.Parameters.Add("@BeginText",
OleDb.OleDbType.Integer, 0, "BeginText")
da.InsertCommand.Parameters.Add("@Length",
OleDb.OleDbType.Integer, 0, "Length")
da.InsertCommand.Parameters.Add("@PointOfView",
OleDb.OleDbType.Integer, 0, "PointOfView")
da.InsertCommand.Parameters.Add("@PermissionID",
OleDb.OleDbType.Integer, 0, "PermissionID")
da.InsertCommand.Parameters.Add("@Publisher",
OleDb.OleDbType.Integer, 0, "Publisher")
da.InsertCommand.Parameters.Add("@CreateDate",
OleDb.OleDbType.Date, 8, "CreateDate")
da.InsertCommand.Parameters.Add("@ChangeDate",
OleDb.OleDbType.Date, 8, "ChangeDate")
da.InsertCommand.Parameters.Add("@Active",
OleDb.OleDbType.Boolean, 2, "Active")
Try
da.Update(dsA, "Topics")
Catch er As System.Exception
MessageBox.Show("Type = " &
er.GetType.ToString & vbCr & "Message = " & er.Message)
'Finally
' cn.Close()
End Try
'You now have access to all fields in the last
row through the DataRow object (dr)
cn.Close()
End Function
Friend Sub OnRowUpDated(ByVal sender As Object, ByVal
args As OleDb.OleDbRowUpdatedEventArgs)
'include a variable and a command to retrieve the
'identity value from the access database
'Dim strConn, strSQL As String
'strConn = "Provider=Microsoft.Jet.OLEDB.4.0;OLE
DB Services=-4;Data Source=H:\HasbaraNET\ado.net
tests\Topics.mdb;"
'Dim cn As New OleDbConnection(strConn)
'MsgBox("before cn open")
'cn.Open()
Dim int1 As Integer = 0
Dim cmd1 As OleDb.OleDbCommand = New
OleDb.OleDbCommand("SELECT @@IDENTITY", cn)
If args.StatementType = StatementType.Insert Then
'Retrieve the identity value and store it in
the ID column
int1 = CInt(cmd1.ExecuteScalar)
MsgBox(int1)
End If
End Sub
and,
Friend Sub OnRowUpDated(ByVal sender As Object,
ByVal args As OleDb.OleDbRowUpdatedEventArgs)
'include a variable and a command to retrieve the
'identity value from the access database
'Dim strConn, strSQL As String
'strConn = "Provider=Microsoft.Jet.OLEDB.4.0;OLE
DB Services=-4;Data Source=H:\HasbaraNET\ado.net
tests\Topics.mdb;"
'Dim cn As New OleDbConnection(strConn)
'MsgBox("before cn open")
'cn.Open()
Dim int1 As Integer = 0
Dim cmd1 As OleDb.OleDbCommand = New
OleDb.OleDbCommand("SELECT @@IDENTITY", cn)
If args.StatementType = StatementType.Insert Then
'Retrieve the identity value and store it in
the ID column
int1 = CInt(cmd1.ExecuteScalar)
MsgBox(int1)
End If
End Sub
If Kevin or somebody else can point me in the right
direction, I'd be very thankful.
dennis
error message.
type = system.data.oledb.oledbexception
message = parameter?_3 has no default value.
First, I've gotten this far thanks mostly to Kevin Yu.
So I have confidence in the rest of the code. I'll put
the relevant code at the end. I've checked help, several
books and msdn for specific information on translating
microsoft access types to ado.net insert statements,
without getting any help.
One book had an example with a boolean, integer and
string types, so I'm fairly confident about those. Here
is an example of one of my parameer statements:
da.InsertCommand.Parameters.Add("@Issuer",
OleDb.OleDbType.Integer, 0, "Issuer")
Nowhere in the literature did I find what number to put
after the type. Especially after the memo type, or what
the number even stands for. In ado.net core reference
these numbers aren't even put in. However the example in
the other book worked, so I guess this syntax is also
valid.
The parameter 3 is topic issuer, which is an integer. You
can see in the code below my message box statement. This
verified that the number was okay and correct. I'm
assuming the list is 0 based, and issuer is actually the
fourth field. I didn't include the autoincrementing ID.
Another mystery is why intellisense insists the third
field is _Text. Nowhere in the access design mode is
this field begun with an underscore or a space. Might it
be related to its being a memo field?
Anyway, here is the relevant code:
Public Function NewTopic(frm as frmTopicFromStart) As
Boolean
NewTopic = False
'Dim cn As New OleDbConnection(gstrConn)
Try
cn.Open()
Catch er As Exception
MessageBox.Show("Type = " &
er.GetType.ToString & vbCr & "Message = " & er.Message)
End Try
'Dim da As OleDbDataAdapter = New OleDbDataAdapter
'Dim ds As New DataSet
'ds.DataSetName = "ds1"
'cn.Open()
'da.FillSchema(ds, SchemaType.Source, "Topics")
''cn.Close()
'ds.WriteXmlSchema("H:\HasbaraNET\ado.net
tests\CodeUpdate\ds.xsd")
Dim cmd As New OleDbCommand("SELECT * FROM
Topics", cn)
Dim da As OleDbDataAdapter = New OleDbDataAdapter
da.SelectCommand = cmd
' Fill the DataSet
Dim ds As DataSet = New DataSet
ds.DataSetName = "ds1"
'da.FillSchema(ds, SchemaType.Source, "Topics")
'ds.WriteXmlSchema("H:\HasbaraNET\ado.net
tests\TFSNet2\ds.xsd")
'da.Fill(ds, "Topics")
Dim dsA As New ds1
da.Fill(dsA, "Topics")
Dim tblTopics As ds1.TopicsDataTable = dsA.Tables
(0)
Dim rowTopics As ds1.TopicsRow
''Dim dr As DataRow
'Dim iRow As Integer
'iRow = dsA.Tables(0).Rows.Count - 1
'rowTopics = dsA.Tables(0).Rows(iRow)
'MsgBox(rowTopics.Issuer.ToString)
'isn't working because no rows
rowTopics = tblTopics.NewTopicsRow
rowTopics.ParentID = CInt(frm.txtParentID.Text)
rowTopics.Title = frm.txtTopicTitle.Text
rowTopics._Text = frm.txtTextGeneral.Text
rowTopics.Issuer =
frm.cboTopicIssuers.SelectedValue
MsgBox(rowTopics.Issuer.ToString)
rowTopics.BeginText = 0
rowTopics.Length = frm.txtTextGeneral.TextLength
rowTopics.PointOfView = frm.cboPOV.SelectedValue
rowTopics.PermissionID = CInt
(frm.txtPermission.Text)
rowTopics.Publisher =
frm.cboPublications.SelectedValue
rowTopics.CreateDate = Now
rowTopics.ChangeDate = Now
rowTopics.Active = True
'rowTopics.PermissionID = 6
MsgBox(rowTopics._Text.GetType.ToString())
'rowTopics.ID = 11
'rowTopics.ID = Integer.MaxValue
tblTopics.AddTopicsRow(rowTopics)
'da.InsertCommand = New OleDb.OleDbCommand
("INSERT INTO Topics
(ID,Topics,CreateDate,ChangeDate,Active) values
(?,?,?,?,?)", cn)
da.InsertCommand = New OleDb.OleDbCommand("INSERT
INTO Topics
(ParentID,Title,_Text,Issuer,BeginText,Length,PointOfView,
PermissionID,Publisher,CreateDate,ChangeDate,Active)
values (?,?,?,?,?,?,?,?,?,?,?,?)", cn)
'INSERT INTO [Order Details] (OrderID, ProductID,
Quantity, UnitPrice) VALUES (?, ?, ?, ?)
'Dim cmdGetIdentity As New OleDbCommand("SELECT
@@IDENTITY", cn)
AddHandler da.RowUpdated, AddressOf OnRowUpDated
'Try
' da.InsertCommand.Parameters.Add("@ID",
OleDb.OleDbType.Integer, 4, "ID")
'Catch er As Exception
' MessageBox.Show("Type = " &
er.GetType.ToString & vbCr & "Message = " & er.Message)
'End Try
da.InsertCommand.Parameters.Add("@ParentID",
OleDb.OleDbType.Integer, 0, "ParentID")
da.InsertCommand.Parameters.Add("@Title",
OleDb.OleDbType.VarChar, 255, "Title")
da.InsertCommand.Parameters.Add("@_Text",
OleDb.OleDbType.LongVarChar, 0, "_Text")
da.InsertCommand.Parameters.Add("@Issuer",
OleDb.OleDbType.Integer, 0, "Issuer")
da.InsertCommand.Parameters.Add("@BeginText",
OleDb.OleDbType.Integer, 0, "BeginText")
da.InsertCommand.Parameters.Add("@Length",
OleDb.OleDbType.Integer, 0, "Length")
da.InsertCommand.Parameters.Add("@PointOfView",
OleDb.OleDbType.Integer, 0, "PointOfView")
da.InsertCommand.Parameters.Add("@PermissionID",
OleDb.OleDbType.Integer, 0, "PermissionID")
da.InsertCommand.Parameters.Add("@Publisher",
OleDb.OleDbType.Integer, 0, "Publisher")
da.InsertCommand.Parameters.Add("@CreateDate",
OleDb.OleDbType.Date, 8, "CreateDate")
da.InsertCommand.Parameters.Add("@ChangeDate",
OleDb.OleDbType.Date, 8, "ChangeDate")
da.InsertCommand.Parameters.Add("@Active",
OleDb.OleDbType.Boolean, 2, "Active")
Try
da.Update(dsA, "Topics")
Catch er As System.Exception
MessageBox.Show("Type = " &
er.GetType.ToString & vbCr & "Message = " & er.Message)
'Finally
' cn.Close()
End Try
'You now have access to all fields in the last
row through the DataRow object (dr)
cn.Close()
End Function
Friend Sub OnRowUpDated(ByVal sender As Object, ByVal
args As OleDb.OleDbRowUpdatedEventArgs)
'include a variable and a command to retrieve the
'identity value from the access database
'Dim strConn, strSQL As String
'strConn = "Provider=Microsoft.Jet.OLEDB.4.0;OLE
DB Services=-4;Data Source=H:\HasbaraNET\ado.net
tests\Topics.mdb;"
'Dim cn As New OleDbConnection(strConn)
'MsgBox("before cn open")
'cn.Open()
Dim int1 As Integer = 0
Dim cmd1 As OleDb.OleDbCommand = New
OleDb.OleDbCommand("SELECT @@IDENTITY", cn)
If args.StatementType = StatementType.Insert Then
'Retrieve the identity value and store it in
the ID column
int1 = CInt(cmd1.ExecuteScalar)
MsgBox(int1)
End If
End Sub
and,
Friend Sub OnRowUpDated(ByVal sender As Object,
ByVal args As OleDb.OleDbRowUpdatedEventArgs)
'include a variable and a command to retrieve the
'identity value from the access database
'Dim strConn, strSQL As String
'strConn = "Provider=Microsoft.Jet.OLEDB.4.0;OLE
DB Services=-4;Data Source=H:\HasbaraNET\ado.net
tests\Topics.mdb;"
'Dim cn As New OleDbConnection(strConn)
'MsgBox("before cn open")
'cn.Open()
Dim int1 As Integer = 0
Dim cmd1 As OleDb.OleDbCommand = New
OleDb.OleDbCommand("SELECT @@IDENTITY", cn)
If args.StatementType = StatementType.Insert Then
'Retrieve the identity value and store it in
the ID column
int1 = CInt(cmd1.ExecuteScalar)
MsgBox(int1)
End If
End Sub
If Kevin or somebody else can point me in the right
direction, I'd be very thankful.
dennis