parallel programming
-
I have created a web application for inserting and updating a set of record using C#.net. the coding is as follows. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class insert : System.Web.UI.Page { SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\PRAVINR\Documents\Visual Studio 2010\WebSites\strikers\App_Data\royal.mdf;Integrated Security=True;User Instance=True"); protected void Page_Load(object sender, EventArgs e) { DataBind(); } protected void Button1_Click(object sender, EventArgs e) { try { con.Open(); SqlCommand cmd = new SqlCommand("insert rusty values(@CustID,@Name,@Address,@City,@Pin,@State,@Country,@ContactNO)", con); cmd.Parameters.AddWithValue("@CustID", TextBox1.Text); cmd.Parameters.AddWithValue("@Name", TextBox2.Text); cmd.Parameters.AddWithValue("@Address", TextBox3.Text); cmd.Parameters.AddWithValue("@City", TextBox4.Text); cmd.Parameters.AddWithValue("@Pin", TextBox5.Text); cmd.Parameters.AddWithValue("@State", TextBox6.Text); cmd.Parameters.AddWithValue("@Country", TextBox7.Text); cmd.Parameters.AddWithValue("@ContactNO", TextBox8.Text); cmd.ExecuteNonQuery(); Label1.Text = "Inserted Completed.."; } catch (Exception ex) { Label1.Text = ex.ToString(); } finally { con.Close(); } } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; TextBox5.Text = ""; TextBox6.Text = ""; TextBox7.Text = ""; TextBox8.Text = ""; } } i need to change the coding to parallel processing so that the process of inserting is done parallel. Can anyone help me solving this ?
-
I have created a web application for inserting and updating a set of record using C#.net. the coding is as follows. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class insert : System.Web.UI.Page { SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\PRAVINR\Documents\Visual Studio 2010\WebSites\strikers\App_Data\royal.mdf;Integrated Security=True;User Instance=True"); protected void Page_Load(object sender, EventArgs e) { DataBind(); } protected void Button1_Click(object sender, EventArgs e) { try { con.Open(); SqlCommand cmd = new SqlCommand("insert rusty values(@CustID,@Name,@Address,@City,@Pin,@State,@Country,@ContactNO)", con); cmd.Parameters.AddWithValue("@CustID", TextBox1.Text); cmd.Parameters.AddWithValue("@Name", TextBox2.Text); cmd.Parameters.AddWithValue("@Address", TextBox3.Text); cmd.Parameters.AddWithValue("@City", TextBox4.Text); cmd.Parameters.AddWithValue("@Pin", TextBox5.Text); cmd.Parameters.AddWithValue("@State", TextBox6.Text); cmd.Parameters.AddWithValue("@Country", TextBox7.Text); cmd.Parameters.AddWithValue("@ContactNO", TextBox8.Text); cmd.ExecuteNonQuery(); Label1.Text = "Inserted Completed.."; } catch (Exception ex) { Label1.Text = ex.ToString(); } finally { con.Close(); } } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; TextBox5.Text = ""; TextBox6.Text = ""; TextBox7.Text = ""; TextBox8.Text = ""; } } i need to change the coding to parallel processing so that the process of inserting is done parallel. Can anyone help me solving this ?
-
I have created a web application for inserting and updating a set of record using C#.net. the coding is as follows. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class insert : System.Web.UI.Page { SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\PRAVINR\Documents\Visual Studio 2010\WebSites\strikers\App_Data\royal.mdf;Integrated Security=True;User Instance=True"); protected void Page_Load(object sender, EventArgs e) { DataBind(); } protected void Button1_Click(object sender, EventArgs e) { try { con.Open(); SqlCommand cmd = new SqlCommand("insert rusty values(@CustID,@Name,@Address,@City,@Pin,@State,@Country,@ContactNO)", con); cmd.Parameters.AddWithValue("@CustID", TextBox1.Text); cmd.Parameters.AddWithValue("@Name", TextBox2.Text); cmd.Parameters.AddWithValue("@Address", TextBox3.Text); cmd.Parameters.AddWithValue("@City", TextBox4.Text); cmd.Parameters.AddWithValue("@Pin", TextBox5.Text); cmd.Parameters.AddWithValue("@State", TextBox6.Text); cmd.Parameters.AddWithValue("@Country", TextBox7.Text); cmd.Parameters.AddWithValue("@ContactNO", TextBox8.Text); cmd.ExecuteNonQuery(); Label1.Text = "Inserted Completed.."; } catch (Exception ex) { Label1.Text = ex.ToString(); } finally { con.Close(); } } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; TextBox5.Text = ""; TextBox6.Text = ""; TextBox7.Text = ""; TextBox8.Text = ""; } } i need to change the coding to parallel processing so that the process of inserting is done parallel. Can anyone help me solving this ?
-
I have created a web application for inserting and updating a set of record using C#.net. the coding is as follows. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class insert : System.Web.UI.Page { SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\PRAVINR\Documents\Visual Studio 2010\WebSites\strikers\App_Data\royal.mdf;Integrated Security=True;User Instance=True"); protected void Page_Load(object sender, EventArgs e) { DataBind(); } protected void Button1_Click(object sender, EventArgs e) { try { con.Open(); SqlCommand cmd = new SqlCommand("insert rusty values(@CustID,@Name,@Address,@City,@Pin,@State,@Country,@ContactNO)", con); cmd.Parameters.AddWithValue("@CustID", TextBox1.Text); cmd.Parameters.AddWithValue("@Name", TextBox2.Text); cmd.Parameters.AddWithValue("@Address", TextBox3.Text); cmd.Parameters.AddWithValue("@City", TextBox4.Text); cmd.Parameters.AddWithValue("@Pin", TextBox5.Text); cmd.Parameters.AddWithValue("@State", TextBox6.Text); cmd.Parameters.AddWithValue("@Country", TextBox7.Text); cmd.Parameters.AddWithValue("@ContactNO", TextBox8.Text); cmd.ExecuteNonQuery(); Label1.Text = "Inserted Completed.."; } catch (Exception ex) { Label1.Text = ex.ToString(); } finally { con.Close(); } } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; TextBox5.Text = ""; TextBox6.Text = ""; TextBox7.Text = ""; TextBox8.Text = ""; } } i need to change the coding to parallel processing so that the process of inserting is done parallel. Can anyone help me solving this ?
-
As far as I can see there is only one
insert
command in the above, so how can that be made parallel (or more likely multi-threaded)?Use the best guess
supposing if there are 2 updates taking place simultaneously the updates takes some time.so to avoid the time delay i need to do it using parallel programming or threading. My main aim is to reduce the CPU work usage.
-
supposing if there are 2 updates taking place simultaneously the updates takes some time.so to avoid the time delay i need to do it using parallel programming or threading. My main aim is to reduce the CPU work usage.
vasanth2vasu wrote:
My main aim is to reduce the CPU work usage.
You do realise that multi-threading actually increases it? And how can you tell when there are two updates in progress since the initiator is the user pressing a button? Your question and your code sample do not make clear exactly what you are trying to achieve, but if all you want to do is to multi-thread some processes, then you should look at the
Thread
class[^].Use the best guess
-
vasanth2vasu wrote:
My main aim is to reduce the CPU work usage.
You do realise that multi-threading actually increases it? And how can you tell when there are two updates in progress since the initiator is the user pressing a button? Your question and your code sample do not make clear exactly what you are trying to achieve, but if all you want to do is to multi-thread some processes, then you should look at the
Thread
class[^].Use the best guess
Can yu give an example in web application where we use parallel processing for inserting and updating SQL database by C#.net simultaneously.
-
Can yu give an example in web application where we use parallel processing for inserting and updating SQL database by C#.net simultaneously.
-
I have created a web application for inserting and updating a set of record using C#.net. the coding is as follows. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; public partial class insert : System.Web.UI.Page { SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\PRAVINR\Documents\Visual Studio 2010\WebSites\strikers\App_Data\royal.mdf;Integrated Security=True;User Instance=True"); protected void Page_Load(object sender, EventArgs e) { DataBind(); } protected void Button1_Click(object sender, EventArgs e) { try { con.Open(); SqlCommand cmd = new SqlCommand("insert rusty values(@CustID,@Name,@Address,@City,@Pin,@State,@Country,@ContactNO)", con); cmd.Parameters.AddWithValue("@CustID", TextBox1.Text); cmd.Parameters.AddWithValue("@Name", TextBox2.Text); cmd.Parameters.AddWithValue("@Address", TextBox3.Text); cmd.Parameters.AddWithValue("@City", TextBox4.Text); cmd.Parameters.AddWithValue("@Pin", TextBox5.Text); cmd.Parameters.AddWithValue("@State", TextBox6.Text); cmd.Parameters.AddWithValue("@Country", TextBox7.Text); cmd.Parameters.AddWithValue("@ContactNO", TextBox8.Text); cmd.ExecuteNonQuery(); Label1.Text = "Inserted Completed.."; } catch (Exception ex) { Label1.Text = ex.ToString(); } finally { con.Close(); } } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; TextBox5.Text = ""; TextBox6.Text = ""; TextBox7.Text = ""; TextBox8.Text = ""; } } i need to change the coding to parallel processing so that the process of inserting is done parallel. Can anyone help me solving this ?
Quote:
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(connStr); string strddl; SqlCommand cmdddl;
Quote:
try { conn.Open(); strddl = "INSERT INTO Users (Username,Name,UserID,Password,UserRoles,SecurityAns) VALUES(@user,@name,@id,@pass,@roles,@Sec)"; cmdddl = new SqlCommand(strddl, conn); cmdddl.Parameters.AddWithValue("@user", TextBox1.Text); cmdddl.Parameters.AddWithValue("@name", TextBox2.Text); cmdddl.Parameters.AddWithValue("@id", CID); cmdddl.Parameters.AddWithValue("@pass", Password.Text); cmdddl.Parameters.AddWithValue("@roles", Role); cmdddl.Parameters.AddWithValue("@Sec", TextBox6.Text); cmdddl.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { Response.Redirect("~/ErrorPage.aspx"); }
Dun't know this code may help on u or not, for the parallel processing is mean wht? i just a newbie :-D