Insert Parameter using .DefaultValue

M

Miro

I created a accessdatasource on my form and it has a parameter for the
insert command.
Then a button to "insert data".
The only way I have found to use that parameter for insert is to use the
..defaultvalue
This seems funny to me.

Instead of doing this:
AccessDataSource1.InsertParameters("AnotherValue").DefaultValue =
TextBox1.Text
AccessDataSource1.Insert()
I was looking to do sometihng like this:
AccessDataSource1.InsertParameters("AnotherValue") = TextBox1.Text
AccessDataSource1.Insert()

or can I only use default value - is that how it is done?

Thanks

Miro


====Code below of control and button ====


<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/mydata.mdb"
DeleteCommand="DELETE FROM [MyFirstTable] WHERE [ID] = ?"
InsertCommand="INSERT INTO [MyFirstTable] ([AnotherValue])
VALUES ( ?)"
SelectCommand="SELECT [ID], [AnotherValue] FROM [MyFirstTable]"
UpdateCommand="UPDATE [MyFirstTable] SET [AnotherValue] = ?
WHERE [ID] = ?">
<DeleteParameters>
<asp:parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="AnotherValue" Type="String" />
<asp:parameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="AnotherValue" Type="String" />
</InsertParameters>
</asp:AccessDataSource>


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
AccessDataSource1.InsertParameters("AnotherValue").DefaultValue =
TextBox1.Text
AccessDataSource1.Insert()
End Sub
 
S

S. Justin Gengo

Miro,

The parameter as gotten here:
AccessDataSource1.InsertParameters("AnotherValue") is an object with
properties that may be accessed. You are then setting one of the properties
like this: AccessDataSource1.InsertParameters("AnotherValue").DefaultValue =
TextBox1.Text.

You should be able to see other properties and/or methods of the object
brought up by intellisense. Technically the .DefaultValue property is what
the parameter will be set to if no other input is received. The .Value
property would override the .DefaultValue property. So you could also set
this by: AccessDataSource1.InsertParameters("AnotherValue").Value =
TextBox1.Text with the same result.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
M

Miro

That doesnt seem to work, ( I tried that )

here is the error I get for the code I have in my Button1_Click:

If TextBox1.Text <> "" Then
'AccessDataSource1.InsertParameters("AnotherValue").DefaultValue
= TextBox1.Text
'This next line is "underlined blue with an error"
AccessDataSource1.InsertParameters("AnotherValue").value =
TextBox1.Text

AccessDataSource1.Insert()
TextBox1.Text = ""
End If

Error
'value' is not a member of 'System.Web.UI.WebControls.Parameter'.
C:\Users\Miro\Documents\Visual Studio
2008\WebSites\DeployTest\Default5.aspx.vb 12 13 C:\...\DeployTest\

The only options I have that I can put after the ("AnotherValue").XXXXX
is this:
ConvertEmptyStringToNull
DBType
DefaultValue
Direction
GetDatabaseType
Name
Size
ToString
Type




"S. Justin Gengo"
Miro,

The parameter as gotten here:
AccessDataSource1.InsertParameters("AnotherValue") is an object with
properties that may be accessed. You are then setting one of the
properties like this:
AccessDataSource1.InsertParameters("AnotherValue").DefaultValue =
TextBox1.Text.

You should be able to see other properties and/or methods of the object
brought up by intellisense. Technically the .DefaultValue property is what
the parameter will be set to if no other input is received. The .Value
property would override the .DefaultValue property. So you could also set
this by: AccessDataSource1.InsertParameters("AnotherValue").Value =
TextBox1.Text with the same result.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche




Miro said:
I created a accessdatasource on my form and it has a parameter for the
insert command.
Then a button to "insert data".
The only way I have found to use that parameter for insert is to use the
.defaultvalue
This seems funny to me.

Instead of doing this:
AccessDataSource1.InsertParameters("AnotherValue").DefaultValue =
TextBox1.Text
AccessDataSource1.Insert()
I was looking to do sometihng like this:
AccessDataSource1.InsertParameters("AnotherValue") = TextBox1.Text
AccessDataSource1.Insert()

or can I only use default value - is that how it is done?

Thanks

Miro


====Code below of control and button ====


<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/mydata.mdb"
DeleteCommand="DELETE FROM [MyFirstTable] WHERE [ID] = ?"
InsertCommand="INSERT INTO [MyFirstTable] ([AnotherValue])
VALUES ( ?)"
SelectCommand="SELECT [ID], [AnotherValue] FROM
[MyFirstTable]"
UpdateCommand="UPDATE [MyFirstTable] SET [AnotherValue] = ?
WHERE [ID] = ?">
<DeleteParameters>
<asp:parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="AnotherValue" Type="String" />
<asp:parameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="AnotherValue" Type="String" />
</InsertParameters>
</asp:AccessDataSource>


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
AccessDataSource1.InsertParameters("AnotherValue").DefaultValue =
TextBox1.Text
AccessDataSource1.Insert()
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top