Showing posts with label action. Show all posts
Showing posts with label action. Show all posts

Friday, March 23, 2012

Problem with INSERT

I've made customcontrol with 3 textboxes, dropdownlist and button.

here is action for button:

protected void Button1_Click(object sender, EventArgs e) { SqlDataSource1.InsertCommand ="insert INTO P ( Numer, Opis, Koszt, id_kli) VALUES('" + nr.Text +"'" +"," +"'" + opisTB.Text +"'" +"," +"'" + kosztTB.Text +"'" +"," +"'" + DropDownList1.SelectedValue +"');"; SqlDataSource1.Insert(); Button1.Visible =false; }
 
the problem is it insert 5 row at once
what should i change.
my db looks like:  P(nr_id(PK), Numer, Opis, Koszt, id_kli);
K(id_kli(PK), Name); 
 
PS
sorry for my english... 

baran:

I've made customcontrol with 3 textboxes, dropdownlist and button.

here is action for button:

protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource1.InsertCommand ="insert INTO P ( Numer, Opis, Koszt, id_kli) VALUES('" + nr.Text +"'" +"," +"'" + opisTB.Text +"'" +"," +"'" + kosztTB.Text +"'" +"," +"'" + DropDownList1.SelectedValue +"');";
SqlDataSource1.Insert();
Button1.Visible =false;
}
 
the problem is it insert 5 row at once
what should i change.
my db looks like:  P(nr_id(PK), Numer, Opis, Koszt, id_kli);
K(id_kli(PK), Name); 

First of all, you should be using parameterized SQL statements. The code you have there, with concatenating UI-supplied data to a SQL string to be executed, is quite insecure. It opens you up to a possibleSQL Injection attack.

If you need to insert 5 rows, wouldn't you create a loop in your code, executing the SQL statement 5 times, each time with different parameter values?

|||

i don't need to insert 5 rows it makes it and i don't know why and how...

i'm noob just getting started

|||

Hi baran,

In this case, I suspect that this event has been fired several times. Please set a breakpoint to see if it has been fired 5 times. Each time should insert 1 record.

Saturday, February 25, 2012

Problem with decimal point

I have got txt file and I am trying to import this file into the database. For that action I use SQL Server Import and Export Wizard. I use Locale Czech and CodePage 1250. In the text file is the column in that format: 18152.65 - it is number with decimal point. When I use BCP utility for importing data, I use datatype decimal(10,2) and everything is OK. But when I try to use Import and Export Wizard, I choose for that column datatype numeric (DT_NUMERIC - precision 10, scale 2), the Import doesn't start and occurs the error:

- Executing (Error)

Messages

Error 0xc02020a1: Data Flow Task: Data conversion failed. The data conversion for column "PRED_CEL " returned status value 2 and status text "The value could not be converted because of a potential loss of data.".
(SQL Server Import and Export Wizard)

Is it always a precision of 10, and a scale of 2? You may have some inconsistent data. There's two things you could do.

1) Increase the precision and scale.

or

2) Create a custom SSIS package, and redirect the error rows to see where the data inconsistency is. The Import/Export Wizard is great for straight forward tasks, but you'll find that with the smallest blib you'll need to create a custom package.

|||The import is very picky about number formats when importing from flat files. It will NOT import zero padded numbers into a decimal field. Even though it will implicetly convert it internally.

For example:
3.99 - OK
003.99 - FAILS
+003.99 - OK
-003.00 - OK

If you import "003.99" into a varchar(12) and then update a decimal(10,2), with the value of teh varchar, it will work fine.