TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mohit Kumar
NA
11
1.2k
Trying to insert multiple rows data of Dataset in a table.
Mar 7 2019 2:45 PM
I wrote a code to insert multiple rows from dataset into a sql table. I put insert inside foreach loop scope but it take first row only.
Please check the code below
string
query, feetype, feename, feeamt;
//Get Fees charges from Fees
Master sda =
new
SqlDataAdapter(
"select class,fees_type,fess_name, fee_amount from tb_fee_master where class='"
+ stclass +
"' and not fees_type='Monthly'"
, sc);
ds =
new
DataSet();
sda.Fill(ds,
"t"
);
if
(ds.Tables[0].Rows.Count != 0)
{
stclass = ds.Tables[0].Rows[0][0].ToString();
feetype = ds.Tables[0].Rows[0][1].ToString();
feename = ds.Tables[0].Rows[0][2].ToString();
feeamt = ds.Tables[0].Rows[0][3].ToString();
int
x = 0;
foreach
(DataRow dr
in
ds.Tables[0].Rows)
{
if
(dr.Table.Rows.Count > 0)
{
query =
"insert into tb_std_fee (class,fee_type,fee_name, amount) values (@class,@fee_type,@fee_name, @amount)"
;
cmd =
new
SqlCommand(query, sc);
cmd.Parameters.AddWithValue(
"@class"
, stclass);
cmd.Parameters.AddWithValue(
"@fee_type"
, feetype);
cmd.Parameters.AddWithValue(
"@fee_name"
, feename);
cmd.Parameters.AddWithValue(
"@amount"
, feeamt);
sc.Open();
x = cmd.ExecuteNonQuery();
sc.Close();
}
}
if
(x != 0)
{
MessageBox.Show(
"Fees register created successfully."
);
}
}
Reply
Answers (
2
)
disable Windows 10 in the upgrade
Creating copy of uploaded file