select and insert to database

V

ven

Hello

i have two tables in my MS SQL named table1 and table2. In each table i have
a column PRICE with my own datatype decimal 14;4 allows nulls....
now i wanna select from one table to second table and i can do it
here is my code :

select * from table1

dim variable = datareader("PRICE")

insert into [table2] ([price]) values ('" + variable "')

i have following error :


Server Error in '/sklep' Application.
----------------------------------------------------------------------------
----

Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct
format.

Source Error:

Line 189: Dim dbConnection1 As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionString)
Line 190: dim czas as datetime =datetime.now
Line 191: Dim queryString1 As String = "INSERT INTO
[zamowienie_intak] ([numer_zamowienia], [data_zamowienia], [id_towar],
[ilosc_towar],[cena_netto],[cena_brutto], [vat], [jednostka]) VALUES ('" +
numer_zam + "','" + today + "', '" + com + "', 1 ,'" + cena_netto_zam +
"','" + cena_brutto_zam +"','" + vat_zam +"','" + jednostka_zam +"')"
Line 192: Dim dbCommand1 As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
Line 193: dbCommand1.CommandText = queryString1

Source File: C:\Inetpub\wwwroot\sklep\search.aspx Line: 191

Stack Trace:

[FormatException: Input string was not in a correct format.]
System.Number.StringToNumber(String str, NumberStyles options,
NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2179309
System.Number.ParseDouble(String value, NumberStyles options,
NumberFormatInfo numfmt) +97
System.Double.Parse(String s, NumberStyles style, NumberFormatInfo info)
+189
Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String
Value, NumberFormatInfo NumberFormat) +213
Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value,
NumberFormatInfo NumberFormat) +78

[InvalidCastException: Conversion from string "INSERT INTO
[zamowienie_intak] (" to type 'Double' is not valid.]
Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value,
NumberFormatInfo NumberFormat) +224
Microsoft.VisualBasic.CompilerServices.Operators.AddObject(Object Left,
Object Right) +2736
ASP.search_aspx.AddToCart(Object Src, CommandEventArgs Args) in
C:\Inetpub\wwwroot\sklep\search.aspx:191
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
+288

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String eventArgument) +5
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +31
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5157
 
C

Curt_C [MVP]

Select Into

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com


ven said:
Hello

i have two tables in my MS SQL named table1 and table2. In each table i have
a column PRICE with my own datatype decimal 14;4 allows nulls....
now i wanna select from one table to second table and i can do it
here is my code :

select * from table1

dim variable = datareader("PRICE")

insert into [table2] ([price]) values ('" + variable "')

i have following error :


Server Error in '/sklep' Application.
-------------------------------------------------------------------------- --
----

Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct
format.

Source Error:

Line 189: Dim dbConnection1 As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionString)
Line 190: dim czas as datetime =datetime.now
Line 191: Dim queryString1 As String = "INSERT INTO
[zamowienie_intak] ([numer_zamowienia], [data_zamowienia], [id_towar],
[ilosc_towar],[cena_netto],[cena_brutto], [vat], [jednostka]) VALUES ('" +
numer_zam + "','" + today + "', '" + com + "', 1 ,'" + cena_netto_zam +
"','" + cena_brutto_zam +"','" + vat_zam +"','" + jednostka_zam +"')"
Line 192: Dim dbCommand1 As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
Line 193: dbCommand1.CommandText = queryString1

Source File: C:\Inetpub\wwwroot\sklep\search.aspx Line: 191

Stack Trace:

[FormatException: Input string was not in a correct format.]
System.Number.StringToNumber(String str, NumberStyles options,
NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2179309
System.Number.ParseDouble(String value, NumberStyles options,
NumberFormatInfo numfmt) +97
System.Double.Parse(String s, NumberStyles style, NumberFormatInfo info)
+189
Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String
Value, NumberFormatInfo NumberFormat) +213
Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value,
NumberFormatInfo NumberFormat) +78

[InvalidCastException: Conversion from string "INSERT INTO
[zamowienie_intak] (" to type 'Double' is not valid.]
Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value,
NumberFormatInfo NumberFormat) +224
Microsoft.VisualBasic.CompilerServices.Operators.AddObject(Object Left,
Object Right) +2736
ASP.search_aspx.AddToCart(Object Src, CommandEventArgs Args) in
C:\Inetpub\wwwroot\sklep\search.aspx:191
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String eventArgument) +5
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +31
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5157



-------------------------------------------------------------------------- --
 
V

ven

table1 is in database1 and table2 is in other database
price have decimal format 14;4 in MS SQL Server
 

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,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top