Write a web method as follows
public void MethodName(string firstName, string lastName)
{
string FullName = firstName + lastName;
/*INSERT (firstName, lastName, FullName) using INSERT QUERY */
}
Question
I found many answers related to this but its not working pretty well with my code.
I WANT THE CODE IN MY WEBMETHOD in C# which I will be calling on android platform.
I have two columns, Firstname and Lastname. I wish to combine the data of this two columns and INSERT it into third column Fullname.
I get the combination from the following code.
SELECT firstname + lastname AS fullname FROM name
And I wish to insert this in the third column of database.
But when I try the foll. code, the data gets entered into a new row instead of the row that already has the firstname and lastname inserted.
So what can be the proper Insert query with select statement inside it?
I tried selfjoin
too but couldn't get the exact result.
Of course, the foll. query is false but what can be the alterations in this to get the desired query.
string ins3 = "INSERT INTO name (fullname) SELECT firstname + lastname AS fullname FROM name AS name_1 WHERE (firstname = @firstname) and (lastname = @lastname)";
Thanks a ton for going through my question. Waiting for an answer.
Solution
Write a web method as follows
public void MethodName(string firstName, string lastName)
{
string FullName = firstName + lastName;
/*INSERT (firstName, lastName, FullName) using INSERT QUERY */
}
OTHER TIPS
You need update query, rather than insert:
Update name Set Fullname =(SELECT firstname + lastname FROM name WHERE (firstname = @firstname) and (lastname = @lastname))
WHERE (firstname = @firstname) and (lastname = @lastname)