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
Ivan Climov
1k
692
22.6k
How to save changes from “textbox” to database?
Nov 26 2018 2:21 AM
The current entry from "dataGridView1" is displayed in "textBox1".
The user in "textBox1" makes changes.
How to save changes from "textBox" to the database and display in "dataGridView1"?
I enclose the code of my decision.
If the form has several "textBox", "checkBox1", then make an event for each element, somehow troublesome ...
Are there any other more efficient ways to do this?
picture - http://www.imageup.ru/img249/3222168/2018-11-23_15-05-54.png.html
public
partial
class
Frm1UC : UserControl
{
DataTable dt;
OleDbConnection connection;
OleDbDataAdapter adapter;
OleDbCommandBuilder commandBuilder;
static
string
catBD = @
"c:\vs\csharp\db_GridVAccess.accdb"
;
string
connectionString =
string
.Format(
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}"
, catBD);
string
sql =
"SELECT * FROM TreeFolder_tbl"
;
// *** ???????????
public
Frm1UC()
{
InitializeComponent();
}
// *** ???????. ???????? ?????
private
void
Frm1UC_Load(
object
sender, EventArgs e)
{
using
(OleDbConnection cn =
new
OleDbConnection())
{
connection =
new
OleDbConnection(connectionString);
connection.Open();
adapter =
new
OleDbDataAdapter(sql, connection);
commandBuilder =
new
OleDbCommandBuilder(adapter);
dt =
new
DataTable();
adapter.Fill(dt);
dataGridView1.DataSource = dt;
}
}
// ????? ??????
private
void
dataGridView1_SelectionChanged(
object
sender, EventArgs e)
{
textBox1.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
}
// ???????. ????????? ??????
private
void
textBox1_TextChanged(
object
sender, EventArgs e)
{
dataGridView1.CurrentRow.Cells[1].Value = textBox1.Text;
}
// ?????????
public
void
Save()
{
adapter.Update(dt);
}
private
void
button1_Click(
object
sender, EventArgs e)
{
Save();
}
}
Reply
Answers (
3
)
Thread sleep until a new day
Hi sir please Provide Your Suggestion