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
Jim Tat
NA
52
47.2k
How to fill DataGridView Cells on cellvaluechanged in MYSQL
Apr 29 2017 5:31 AM
I have a DataGridView in which there are 4 columns; Reference,Quantity, Rate and Amount.
The DataGridView is Editable. When I enter a value in the Reference Column then immediately it will fill the other values in the others cells from mysql database.
This is what I tried....
private
void
TAB_Credit_CellValueChanged(
object
sender, DataGridViewCellEventArgs e)
{
try
{
if
(TAB_Credit.CurrentCell.ColumnIndex == 0)
{
MySqlDataAdapter sa =
new
MySqlDataAdapter(
"SELECT * FROM table WHERE Reference='"
+ TAB_Credit.Rows[e.RowIndex].Cells[
"Reference"
].Value +
"'"
, MyConnexion);
DataTable dt2 =
new
DataTable();
sa.Fill(dt2);
double
value = (
double
)TAB_Credit.Rows[e.RowIndex].Cells[
"Quantite"
].Value * (
double
)TAB_Credit.Rows[e.RowIndex].Cells[
"PU"
].Value;
TAB_Credit.Rows[e.RowIndex].Cells[
"Designation"
].Value = dt2.Rows[0][
"Designation"
].ToString();
TAB_Credit.Rows[e.RowIndex].Cells[
"Quantite"
].Value = dt2.Rows[0][
"Quantite"
].ToString();
TAB_Credit.Rows[e.RowIndex].Cells[
"PU"
].Value = dt2.Rows[0][
"Prix_Unitaire"
].ToString();
TAB_Credit.Rows[e.RowIndex].Cells[
"Total"
].Value = value.ToString();
}
}
catch
{ }
}
So in the datagrid, when I insert in the Reference Cell nothing is appearing in the other cells.
Thank you.
Reply
Answers (
2
)
Best way to read from Datatable and return JsonResult IN MVC
Filling datagridview cells after validating first row in C#