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
Israel
699
1.3k
217.5k
How to Insert between record
Feb 28 2020 8:11 AM
Hi,
There is any way to insert a record as it’s possible with edit if you want to edit a table from datagrid. For example I need to insert between row nº 3 and 4 a record. How can do this:
ID Date Account
1
2
3
//Insert here
4
5
When I need to edit a some rows I do this:
conn =
new
SqlConnection(
"Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename=C:\\xxx\\xx\\App_Datas\\test.mdf;Integrated Security = True"
);
comm =
new
SqlCommand();
if
(conn.State != ConnectionState.Open)
conn.Open();
SqlCommand comm1 =
new
SqlCommand();
comm1.Connection = conn;
SqlParameter dat =
new
SqlParameter(
"@dat"
, SqlDbType.Date);
SqlParameter account =
new
SqlParameter(
"@account"
, SqlDbType.VarChar);
SqlParameter ID =
new
SqlParameter(
"@ID"
, SqlDbType.Int);
comm1.Parameters.Add(dat);
comm1.Parameters.Add(account);
comm1.Parameters.Add(ID);
data.Value = dtDate.Text;
conta.Value = txtAccount.Text;
ID.Value = lblID.Text;
comm1.Connection = conn;
comm1.CommandText =
"UPDATE test1 SET date = @date, account = @ account, WHERE (ID = @ID)"
;
{
if
(MessageBox.Show(
"Do you want to insert this record?"
,
"Insert Record"
, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
try
{
comm1.ExecuteNonQuery();
}
finally
{
dgvTest.CurrentCell = dgvTest.Rows[dgvTest.Rows.Count - 1].Cells[0];
conn.Close(); }
}
Reply
Answers (
2
)
Needed to remove double quote from json object key only
How to Compare between Hashed Password