Search:
Namespaces
Discussions
.NET v1.1
Feedback
Insert records whose values increment
Messages
Related Types
This message was discovered on
ASPFriends.com 'ngfx-sqlclient' list
.
Jon Le
-- Moved from [aspngdata] to [ngfx-sqlclient] by Let the good times roll <
Click here to reveal e-mail address
> --
I was wondering if someone can help me with the following code, which
is behind a web form.
String insertCmd = "insert into dbo.ar_gl_mid_lvl_code_new values
(@major_payor," +
" @sub_payor, @patclass, @mid_lvl_code)";
// Initialize the
SqlCommand
with the new SQL string
// and the connection information.
SqlCommand
myCommand = new
SqlCommand
(insertCmd, myConnection);
int StartValue =
Convert
.ToInt32(this.txtMidCodeStartValue.Text);
int EndValue =
Convert
.ToInt32(this.txtMidCodeEndValue.Text);
string Mcode = this.ddlMRMC.SelectedItem.Value;
int MajorPayor =
Convert
.ToInt32 (this.txtMajorPayorNo.Text);
int SubPayor =
Convert
.ToInt32 (this.txtSubPayorNo.Text);
char PatClass =
Convert
.ToChar (this.ddlIO.SelectedItem.Text);
// Create new parameters for the
SqlCommand
object and
// initialize them to the input-form field values.
myCommand.Parameters.Add(new
SqlParameter
("@major_payor",
SqlDbType
.Int,
2));
myCommand.Parameters.Add(new
SqlParameter
("@sub_payor",
SqlDbType
.Int,
2));
myCommand.Parameters.Add(new
SqlParameter
("@patclass",
SqlDbType
.Char,
2));
myCommand.Parameters.Add(new
SqlParameter
("@mid_lvl_code",
SqlDbType
.VarChar, 10));
int n;
for (n = StartValue; n <= EndValue; n++)
{
/*Right now, this logic just inserts one record, the last instance of
"n". I would like to insert all records up to the last instance of
"n". How can I do that? I have done this with a dropdownlist control
because it has an "add" method. Does the
SqlCommand
object have a
similiar method? How can I implement it?
*/
myCommand.Parameters["@major_payor"].Value = MajorPayor;
myCommand.Parameters["@sub_payor"].Value = SubPayor;
myCommand.Parameters["@patclass"].Value = PatClass;
myCommand.Parameters["@mid_lvl_code"].Value = Mcode +
(
Convert
.ToString(n).PadLeft(8,'0'));
}
//open db connection, execute, close
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
}
Thank you in advance for your help.
__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com
Reply to this message...
Calhoun, Matthew
All you should have to do is put the=20
"myCommand.Connection.Open();" before your for loop and
"myCommand.ExecuteNonQuery();" inside your for loop. This will execute
the insert for each item in the loop.
-----Original Message-----
From: Jon Le [mailto:
Click here to reveal e-mail address
]=20
Sent: Friday, July 26, 2002 5:19 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Insert records whose values increment
-- Moved from [aspngdata] to [ngfx-sqlclient] by Let the good times roll
<
Click here to reveal e-mail address
> --
I was wondering if someone can help me with the following code, which
is behind a web form. =20
String insertCmd =3D "insert into dbo.ar_gl_mid_lvl_code_new values
(@major_payor," +
" @sub_payor, @patclass, @mid_lvl_code)";
=09
// Initialize the
SqlCommand
with the new SQL string=20
// and the connection information.
SqlCommand
myCommand =3D new
SqlCommand
(insertCmd, myConnection);
int StartValue =3D
Convert
.ToInt32(this.txtMidCodeStartValue.Text);
int EndValue =3D
Convert
.ToInt32(this.txtMidCodeEndValue.Text);
string Mcode =3D this.ddlMRMC.SelectedItem.Value;
=09
int MajorPayor =3D
Convert
.ToInt32 (this.txtMajorPayorNo.Text);
int SubPayor =3D
Convert
.ToInt32 (this.txtSubPayorNo.Text);
char PatClass =3D
Convert
.ToChar (this.ddlIO.SelectedItem.Text);
=09
// Create new parameters for the
SqlCommand
object and
// initialize them to the input-form field values.
myCommand.Parameters.Add(new
SqlParameter
("@major_payor",
SqlDbType
.Int,
2));
myCommand.Parameters.Add(new
SqlParameter
("@sub_payor",
SqlDbType
.Int,
2));
myCommand.Parameters.Add(new
SqlParameter
("@patclass",
SqlDbType
.Char,
2));
myCommand.Parameters.Add(new
SqlParameter
("@mid_lvl_code",
SqlDbType
.VarChar, 10));
int n;
for (n =3D StartValue; n <=3D EndValue; n++)
{
/*Right now, this logic just inserts one record, the last instance of
"n". I would like to insert all records up to the last instance of
"n". How can I do that? I have done this with a dropdownlist control
because it has an "add" method. Does the
SqlCommand
object have a
similiar method? How can I implement it?
*/
=09
myCommand.Parameters["@major_payor"].Value =3D MajorPayor;
myCommand.Parameters["@sub_payor"].Value =3D SubPayor;
myCommand.Parameters["@patclass"].Value =3D PatClass;
myCommand.Parameters["@mid_lvl_code"].Value =3D Mcode +
(
Convert
.ToString(n).PadLeft(8,'0'));
}
=09
//open db connection, execute, close
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();=09
}
Thank you in advance for your help.
__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com
| [ngfx-sqlclient] member
Click here to reveal e-mail address
=3D YOUR ID
|
http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp
=3D JOIN/QUIT
Reply to this message...
System.Convert
System.Data.SqlClient.SqlCommand
System.Data.SqlClient.SqlParameter
System.Data.SqlDbType
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com