Showing posts with label insertcommand. Show all posts
Showing posts with label insertcommand. Show all posts

Wednesday, March 28, 2012

InsertCommand, add strings...

I am submitting a telephone number into a table. I have 3 boxes for the telephone number. Telephone1,Telephone2,Telephone3. I need to insert the values of the 3 text boxes into a column called phone in my table.

so like

InsertCommand="INSERT INTO customer_mod (phone) Values (@.Telephone_1)

<asp:formparameter name="Telephone_1" formfield="Telephone1+Telephone2+Telephone3" />

I don't think that is gonna work, so can you please help me make that code work?

I think you'll have to write some code for this. Write below code in the submit button click event.

string Telephone =string.Empty;
Telephone = Telephone1.Text +"-" + Telephone2.Text +"-" + Telephone3.Text;
SqlDataSource1.InsertParameters.Add("@.Telephone", Telephone);
SqlDataSource1.Insert();

Hope this will help.

|||

That works, but then it does not submit any of my other data. I have data being inserted into the database using...

InsertCommand="INSERT INTO customer_mod (CsrAgent,FirstName,LastName,Address1,City1,State1,Zipcode1,

InstallAddress,InstallCity,InstallState,InstallZip,CrossStreets,InstallDate,InstallTimes,InstallTimesOther)

When using this on the button...

string phone =string.Empty;

phone = Telephone1.Text + Telephone2.Text + Telephone3.Text;

SqlDataSource1.InsertParameters.Add("@.phone", phone);

SqlDataSource1.InsertCommand ="INSERT INTO [customer_mod](phone) values ('" + phone +"')";

SqlDataSource1.Insert();

Only the data is shown. So basically it is only accepting one insert. Can I not use insert from my aspx page and cs page?

|||

This was just to demonstrate you how you can merge the telephone numbers. In order to pass all other values, you just need to pass the value for each column as a parameter. So your insert query would be like:

INSERT INTO customer_mod ( CsrAgent , FirstName , LastName , Address1 , City1 , State1 , Zipcode1 , InstallAddress , InstallCity , InstallState , InstallZip , CrossStreets , InstallDate , InstallTimes , InstallTimesOther )values ( @.CsrAgent , @.FirstName , @.LastName , @.Address1 , @.City1 , @.State1 , @.Zipcode1 , @.InstallAddress , @.InstallCity , @.InstallState , @.InstallZip , @.CrossStreets , @.InstallDate , @.InstallTimes , @.InstallTimesOther )

and you'll have to add the value for each of the above parameters just like you did for phone number. Get the value from the text box or any other control on your form and pass it to the value for that parameter.

InsertCommand using data from a second SqlDataSource - ASP.NET 2.0

I have a process that inserts a new record using the InsertCommand of aSqlDataSource. As part of the process, I need to insert data the is available in a different SqlDataSource. I was trying this with the Insert Parameter:

<asp:FormParameterName="Change_Title"FormField="Change_Title"/>

where Change_Title is available on screen. Doesn't work. Is this possible?

HI

Can you see if this post helps or gives you some idea of how to achieve it.

http://forums.asp.net/p/1124558/1766373.aspx#1766373

The post though gives a way to avoid the need for two SQLDatasources but use one to handle both level updates.

Hope this helps.

VJ