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
girmachew gulint
NA
85
1.8k
Insert data to sql server from Textbox which is in a loop
Nov 6 2019 12:44 PM
Getting data from SQL Table
using
(var con =
new
SqlConnection(constr))
{
string
query =
"select * from higher_office"
;
using
(var cmd =
new
SqlCommand(query, con))
{
using
(var sda =
new
SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using
(TableData)
{
TableData.Clear();
sda.Fill(TableData);
}
}
}
}
aspx fetched data and new Textbox for inputing values corresponding to higher office
<%
for
(var data = 0; data < TableData.Rows.Count; data++)
{
%>
<tr>
<td>
<%=TableData.Rows[data][
"higher_office_ID"
]%>
</td>
<td>
<%=TableData.Rows[data][
"higher_office_Name"
]%>
</td>
<td>
<asp:TextBox ID=
"TextBox1"
runat=
"server"
width=
"150px"
></asp:TextBox>
</td>
</tr>
<% } %>
trying to insert as follows but not excute
using
(SqlConnection con =
new
SqlConnection(constr))
{
con.Open();
//SqlCommand cm = new SqlCommand("insert into item_distribution (sector,quantity) values('" + id + "','" + amount+ "')", con);
for
(
int
i = 1; i <= rowCount; i++)
{
SqlCommand cm =
new
SqlCommand(
"insert into item_distribution (sector,quantity) values('"
+ id +
"','"
+ amount+
"')"
,con);
try
{
cm.ExecuteNonQuery();
RoleMessage.Text +=
"Successfully inserted"
;
RoleMessageDIV.Style[
"display"
] =
"block"
;
}
catch
(Exception ex )
{
RoleMessage.Text +=
"Not inserted "
+ex;
RoleMessageDIV.Style[
"display"
] =
"block"
;
}
}
con.Close();
}
Reply
Answers (
1
)
Show markers on google map and in list underneath.
Note Pad Open Close save button and Editable