| | |
Insert........ Records
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2009
Posts: 4
Reputation:
Solved Threads: 0
Hope for a fruitful reply....................
Enter a number into a textbox(like 5 or 10 or something like that.
Then that number of rows are inserted into the table ..."Master"( id,serial_no,password) .
Like if i enter 10 into that textbox and submit then inserted 10 number of rows into a table ...
Plz Help me ... i have to done it by asp.net using c#.
Enter a number into a textbox(like 5 or 10 or something like that.
Then that number of rows are inserted into the table ..."Master"( id,serial_no,password) .
Like if i enter 10 into that textbox and submit then inserted 10 number of rows into a table ...
Plz Help me ... i have to done it by asp.net using c#.
0
#2 22 Days Ago
You can follow the below way:
ASP.NET Syntax (Toggle Plain Text)
//open your connection here for(int i=0; i<Convert.ToInt(TextBox1.Text);i++) { // insert HERE } //close your connection here
Last edited by mail2saion; 22 Days Ago at 2:21 am.
MARK AS SOLVED if its help you.
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
•
•
Join Date: Nov 2009
Posts: 4
Reputation:
Solved Threads: 0
0
#3 21 Days Ago
Thanks 4 ur fruitful Reply But it gives some error when it insert more than 1 times ..................in a table.
Code:
ADOALL CLASS:
Plz Sir, Give me a Solution... [
]
Code:
ASP.NET Syntax (Toggle Plain Text)
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; using System.Data.SqlClient; public partial class PinGeneration : System.Web.UI.Page { ADOALL aa; private SqlConnection sconn; private SqlCommand scomm; private SqlDataReader sdr; MemoryStream ms = new MemoryStream(); SqlParameter spfull_no,spserial_no,sppassword; string strCommText = "insert into Pin_Generate (id_no, serial_no, password) values(@pfull_no, @pserial_no, @ppassword)"; string strCommText2 = "select last_id from Temp_ID"; public PinGeneration() { sconn = new SqlConnection(); scomm = new SqlCommand(); sconn.ConnectionString = ConfigurationManager.ConnectionStrings["MLMSqlServer"].ConnectionString; scomm.CommandType = CommandType.Text; // scomm.CommandText = strCommText1.Trim(); scomm.CommandText = strCommText2.Trim(); scomm.Connection = sconn; spfull_no = new SqlParameter(); spfull_no.SqlDbType = SqlDbType.VarChar; spfull_no.ParameterName = "pfull_no"; spfull_no.Direction = ParameterDirection.Input; spserial_no = new SqlParameter(); spserial_no.SqlDbType = SqlDbType.VarChar; spserial_no.ParameterName = "pserial_no"; spserial_no.Direction = ParameterDirection.Input; sppassword = new SqlParameter(); sppassword.SqlDbType = SqlDbType.VarChar; sppassword.ParameterName = "ppassword"; sppassword.Direction = ParameterDirection.Input; } protected void Page_Load(object sender, EventArgs e) { lbldate.Text = DateTime.Now.ToString(); try { if (sconn.State == ConnectionState.Closed) { sconn.Open(); sdr = scomm.ExecuteReader(); sdr.Read(); string a = sdr["last_id"].ToString(); int b = Int32.Parse(a); int c = b + 1; lblstatement.Text = "FMS00".ToString() + b; Label3.Text = c.ToString(); lblprint_id.Text = "FMS00".ToString() + c; sconn.Close(); } } catch (Exception ex) { Response.Write(ex.ToString()); } } private int Randam_Number(int min,int max) { Random randam = new Random(); return randam.Next(min,max); } protected void btnsubmit_Click(object sender, EventArgs z) { Randam_Number(14,100); int number = 3490219; lblserial_no.Text=number.ToString(); lblpassword.Text = number.ToString(); int i; for (i = 1; i <= Convert.ToInt32(txtpin_no.Text); i++) { getNum(); spfull_no.Value = lblprint_id.Text; spserial_no.Value = lblserial_no.Text; sppassword.Value = lblpassword.Text; aa = new ADOALL(strCommText, spfull_no, spserial_no, sppassword); int x = 0; try { x = aa.ExecuteStatements(); } catch (SqlException sqlex) { Response.Write(sqlex.ToString()); x = 0; } if (x > 0) { lblmsg.Text = "Successfully Created"; } else { lblmsg.Text = "Please Try Again"; } update(); } } private void getNum() { if (sconn.State == ConnectionState.Closed) { sconn.Open(); scomm.CommandType = CommandType.Text; string strCommText2 = "select last_id from Temp_ID"; scomm.CommandText = strCommText2.Trim(); scomm.Connection = sconn; sdr = scomm.ExecuteReader(); sdr.Read(); string a = sdr["last_id"].ToString(); int b = Int32.Parse(a); int c = b + 1; lblstatement.Text = "FMS00".ToString() + b; Label3.Text = c.ToString(); lblprint_id.Text = "FMS00".ToString() + c; sconn.Close(); } } private void update() { try { if (sconn.State == ConnectionState.Closed) { sconn.Open(); scomm.CommandText = "UPDATE Temp_ID SET last_id='" + Label3.Text + "'"; // WHERE last_id=@last_id"; scomm.Connection = sconn; scomm.ExecuteNonQuery(); sconn.Close(); } } catch (SqlException e) { Response.Write(e.ToString()); } } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { } protected void lblogout_Click(object sender, EventArgs e) { FormsAuthentication.SignOut(); Response.Redirect("super_admin_login"); } }
ADOALL CLASS:
c# Syntax (Toggle Plain Text)
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; /// <summary> /// Summary description for ADOALL /// </summary> public class ADOALL { private SqlConnection sconn; private SqlCommand scomm; private SqlDataReader sdr; public ADOALL(string strCommText, params SqlParameter[] spCollection) { // // TODO: Add constructor logic here // sconn = new SqlConnection(); scomm = new SqlCommand(); sconn.ConnectionString = ConfigurationManager.ConnectionStrings["MLMSqlServer"].ConnectionString; scomm.CommandType = CommandType.Text; scomm.CommandText = strCommText.Trim(); scomm.Connection = sconn; scomm.Parameters.AddRange(spCollection); // Error occurs here... It } public bool ConnOpen() { if (sconn.State == ConnectionState.Closed) { try { sconn.Open(); return true; } catch (Exception) { return false; } } else { return true; } } public bool ConnClose() { if (sconn.State == ConnectionState.Open) { try { sconn.Close(); return true; } catch (Exception) { return false; } } else { return true; } } public bool GetReader() { if (ConnOpen()) { sdr = scomm.ExecuteReader(); if (sdr.Read()) { ConnClose(); return true; } else { ConnClose(); return false; } } else { return false; } } public int ExecuteStatements() { if (ConnOpen()) { int x = scomm.ExecuteNonQuery(); ConnClose(); return x; } return 0; } public SqlDataReader getSqlReader() { if (ConnOpen()) { sdr = scomm.ExecuteReader(CommandBehavior.CloseConnection); return sdr; } else { return null; } } public object getSqlScaler() { if (ConnOpen()) { object ser = scomm.ExecuteScalar(); sconn.Close(); return ser; } else { return null; } } }
Plz Sir, Give me a Solution... [
] Last edited by peter_budo; 20 Days Ago at 9:16 am. Reason: Missing code tags on second code sample
0
#4 20 Days Ago
Its a bit time consuming to read your code. But i can give you one tricks & hope it will resolve your problem.
Wrap all insert related code under loop. I mean within the loop open connection execute statement then close connection. So that for 2nd iteration connection will open again then execute & close so on.
If you can can insert multiple statement in this way then you can optimize your code later.
Wrap all insert related code under loop. I mean within the loop open connection execute statement then close connection. So that for 2nd iteration connection will open again then execute & close so on.
If you can can insert multiple statement in this way then you can optimize your code later.
MARK AS SOLVED if its help you.
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
![]() |
Similar Threads
- Insert multiple records using stored procedure (MS SQL)
- Update/Insert/Delete records based on user one or more selections in list box control (ASP.NET)
- Can i insert a record without WHILE or FOR loop??? (PHP)
- PHP/MySql - Inserting Multiple Records (PHP)
- how to insert records into a table using datacontrol (Visual Basic 4 / 5 / 6)
- Insert into a Dbase file (Pascal and Delphi)
- Exclude duplicate records in a JOIN (MS SQL)
- how to insert data from dataset into database (VB.NET)
- Beginner: Insert, Update, Delete & Search records from/to sql database (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Urgent:Encryption
- Next Thread: c# with vb in asp.net
| Thread Tools | Search this Thread |
.net activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser button c# cac checkbox click commonfunctions control css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownlist dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iframe iis javascript listbox login microsoft mono mouse mssql multistepregistration news novell numerical objects opera panelmasterpagebuttoncontrols radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visualstudio web webapplications webdevelopemnt webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers





