Simple insert with SqlDataSource doesn't work - why?

  • Thread starter Thread starter staeri
  • Start date Start date
S

staeri

I want to insert values from the querystring but nothing happens with
this code (the sp works great from the Query Analyzer):

<form id="form1" runat="server">

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString
%>"InsertCommand="spSearch_row_insert"
InsertCommandType="StoredProcedure">
<InsertParameters>

<asp:QueryStringParameter Name="CustomerID" QueryStringField="1"
DefaultValue="1" Type="String" />

<asp:QueryStringParameter Name="SearchID" QueryStringField="2"
DefaultValue="1" Type="String"/>

<asp:QueryStringParameter Name="SearchDate" QueryStringField="3"
DefaultValue="1" Type="String" />

<asp:QueryStringParameter Name="IP" QueryStringField="4"
DefaultValue="1" Type="String" />

</InsertParameters>

</asp:SqlDataSource>

</form>


I'm very grateful for help!

Regards,

S
 
The Name attribute of a QueryStringParameter refers to the parameter's
name in the sp/query, whereas the QueryStringField refers to the
parameter's name in the QueryString (and not its order number)

You probably should have

<asp:QueryStringParameter Name="CustomerID"
QueryStringField="CustomerID"
DefaultValue="1" Type="String" />


<asp:QueryStringParameter Name="SearchID" QueryStringField="SearchID"
DefaultValue="1" Type="String"/>


<asp:QueryStringParameter Name="SearchDate"
QueryStringField="SearchDate"
DefaultValue="1" Type="String" />


<asp:QueryStringParameter Name="IP" QueryStringField="IP"
DefaultValue="1" Type="String" />
 
No, I've tried also this but still nothing is inserted to the database
and no error message is given. The sp runs perfectly from the Query
Analyzer.
 
Well, are you calling SqlDataSource1.Insert() anywhere in your code?
If not, do you have any control that uses SqlDataSource1 and issues an
"insert" command?
 
No, I was just calling the page by opening it in the browser. Maybe
that's not enough.

How can I call SqlDataSource1.Insert() from my code?
 
You write SqlDataSource1.Insert(); :P
You might want to do this in either Page_Load or in a button click
handler.
I don't understand why you are trying to insert data by opening a
page, though. You could do it in the caller page.
 
Ok, thanks!

The reason why I do is this that I'm logging how a Windows application
is used. Every time a special command is run the the Windows
application on the users computers this is logged over the Internet
into a SQL database.

The easiest way I've found to do this logging is to open the browser
and a aspx page with parameters to insert. Do you have any other
suggestions how to do it?
 
I think it would be cleaner to use a web service, and provide it with
the desired parameters.
 

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

Back
Top