insert problem to access db

  • Thread starter Thread starter Lenny
  • Start date Start date
L

Lenny

I run this code to insert some data into an access db

For i = 1 To 14
a = Master.FindControl("centro").FindControl("a" & i.ToString)
'Response.Write(a.Text)
If Len(a.Text) > 0 Then
SqlDataSource3.InsertParameters.Add("movimento", id)
SqlDataSource3.InsertParameters.Add("importo", a.text)
SqlDataSource3.InsertParameters.Add("sessione",
Session.SessionID)
SqlDataSource3.Insert()
End If
Next

the problem is that event all the sqls run, values into db are all the same:
the first cicle values.
values are taken correctly as I check them with response.write, but there's
no way to put them into db.

any suggestion?
thanks
Lenny
 
I run this code to insert some data into an access db

For i = 1 To 14
a = Master.FindControl("centro").FindControl("a" & i.ToString)
'Response.Write(a.Text)
If Len(a.Text) > 0 Then
SqlDataSource3.InsertParameters.Add("movimento", id)
SqlDataSource3.InsertParameters.Add("importo", a.text)
SqlDataSource3.InsertParameters.Add("sessione",
Session.SessionID)
SqlDataSource3.Insert()
End If
Next

the problem is that event all the sqls run, values into db are all the same:
the first cicle values.
values are taken correctly as I check them with response.write, but there's
no way to put them into db.

any suggestion?
thanks
Lenny

do you mean you have 14 times the same value in "importo"?
 
do you mean you have 14 times the same value in "importo"?

yes.
I changed also the other values saved to understand what is saved, and the
values are always the ones of i=1 for 14 times

Lenny
 
yes.
I changed also the other values saved to understand what is saved, and the
values are always the ones of i=1 for 14 times

Lenny

What is the insertcommand for the SqlDataSource3?
 
What is the insertcommand for the SqlDataSource3?
here it is.

<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:Versamenti %>"
ProviderName="<%$ ConnectionStrings:Versamenti.ProviderName %>"
InsertCommand ="INSERT INTO assegni_euro (Movimento, importo_euro, sessione)
values (:movimento, :importo, :sessione)" DataSourceMode="DataReader" >

</asp:SqlDataSource>

thanks

Lenny
 
here it is.

<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:Versamenti %>"
ProviderName="<%$ ConnectionStrings:Versamenti.ProviderName %>"
InsertCommand ="INSERT INTO assegni_euro (Movimento, importo_euro, sessione)
values (:movimento, :importo, :sessione)" DataSourceMode="DataReader" >

</asp:SqlDataSource>

thanks

Lenny

HA-HA, that's easy...

The InsertParameters.Clear() does the trick

The reason is simple: you have 14 parameters added in the loop and
Insert() method uses only the first one, which is always the same! It
means you should either remove it or clear...

....
If Len(a.Text) > 0 Then
SqlDataSource3.InsertParameters.Clear()
SqlDataSource3.InsertParameters.Add("movimento", id)
....
 
The reason is simple: you have 14 parameters added in the loop and
Insert() method uses only the first one, which is always the same! It
means you should either remove it or clear...

...
If Len(a.Text) > 0 Then
SqlDataSource3.InsertParameters.Clear()
SqlDataSource3.InsertParameters.Add("movimento", id)
...

THAT WORKS !
thank you so much!

Lenny
forever newbie :)
 
Back
Top