This example illustrates
Prepare the database to be used in the example
Create a database named [Wxwinterwftest],
Create a table in the database named [usertable], create a field in the table named [Userud] [Nurchar (50)], set as the primary key
The activity of the operation database to be used in the example
[Insertdatatosqlserveractivity] has an [in parameter] UserID that is used to insert records into the [usertable] table
public sealed class Insertdatatosqlserveractivity:nativeactivity
{
Public inargument<string> UserID {get; set;}
protected override void Execute (Nativeactivitycontext context)
{
Insertusertable (Userid.get (context));
}
void Insertusertable (String UserID)
{
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection ();
Con. ConnectionString = "Data source=.;i Nitial catalog=wxwinterwftest;integrated security=true; ";
Con. Open ();
System.Data.SqlClient.SqlCommand cmd = con. CreateCommand ();
Cmd.commandtext = string. Format ("INSERT into usertable (UserID) VALUES (' {0} ')", UserID);
Cmd. ExecuteNonQuery ();
Con. Close ();
}
}