Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Power Lifting Lever Belt
SkullVamp
Updated:
Saturday at 10:32 PM
Ad icon
port.lk Domain for sale
Lankan-Tech
Updated:
Saturday at 3:55 PM
Colombo
Kaduwela - Two Storey House for Sale
dilrasan
Updated:
Thursday at 2:23 PM
Ad icon
Wechat qr verification
Pawan2005
Updated:
Thursday at 1:28 AM
🚀 GOOGLE AI PRO 18 MONTHS ACTIVATION 🚀
sayuru bandara
Updated:
Jun 10, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
C# - Grid-view to SQL
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="BoraluGoda" data-source="post: 13891337" data-attributes="member: 332053"><p><span style="font-size: 12px">මචංල දන්න කෙනෙක් මට කියල දෙනවද datagridview එක rows තියන data බට්න් ක්ලික් ඉවෙන්ට් එකකදී database එකට සේව් කරගන්න විදිය. මම datagridview එකට ගන්නෙ data table එකකින්. පහල තියෙන්නෙ මම කරපු codes.</span></p><p></p><p>[CODE]using System;</p><p>using System.Collections.Generic;</p><p>using System.Linq;</p><p>using System.Text;</p><p>using System.Data.SqlClient;</p><p></p><p>namespace Billing_App</p><p>{</p><p></p><p></p><p> public class ORD_Class</p><p> {</p><p> String connection = "Data Source=CHANAKA-PC;Initial Catalog=Billing_System_DB;Integrated Security=True";</p><p></p><p> private int mORD_NO;</p><p></p><p> public int MORD_NO</p><p> {</p><p> get { return mORD_NO; }</p><p> set { mORD_NO = value; }</p><p> }</p><p> private String mORD_ID;</p><p></p><p> public String MORD_ID</p><p> {</p><p> get { return mORD_ID; }</p><p> set { mORD_ID = value; }</p><p> }</p><p> private DateTime mORD_Date;</p><p></p><p> public DateTime MORD_Date</p><p> {</p><p> get { return mORD_Date; }</p><p> set { mORD_Date = value; }</p><p> }</p><p> private String mCUS_Name;</p><p></p><p> public String MCUS_Name</p><p> {</p><p> get { return mCUS_Name; }</p><p> set { mCUS_Name = value; }</p><p> }</p><p> private String mCUS_Address;</p><p></p><p> public String MCUS_Address</p><p> {</p><p> get { return mCUS_Address; }</p><p> set { mCUS_Address = value; }</p><p> }</p><p> private String mCUS_Contact;</p><p></p><p> public String MCUS_Contact</p><p> {</p><p> get { return mCUS_Contact; }</p><p> set { mCUS_Contact = value; }</p><p> }</p><p> private String mPRO_Code;</p><p></p><p> public String MPRO_Code</p><p> {</p><p> get { return mPRO_Code; }</p><p> set { mPRO_Code = value; }</p><p> }</p><p> private String mPRO_Name;</p><p></p><p> public String MPRO_Name</p><p> {</p><p> get { return mPRO_Name; }</p><p> set { mPRO_Name = value; }</p><p> }</p><p> private String mPRO_Des;</p><p></p><p> public String MPRO_Des</p><p> {</p><p> get { return mPRO_Des; }</p><p> set { mPRO_Des = value; }</p><p> }</p><p> private Double mPRO_Price;</p><p></p><p> public Double MPRO_Price</p><p> {</p><p> get { return mPRO_Price; }</p><p> set { mPRO_Price = value; }</p><p> }</p><p> private int mPRO_Qty;</p><p></p><p> public int MPRO_Qty</p><p> {</p><p> get { return mPRO_Qty; }</p><p> set { mPRO_Qty = value; }</p><p> }</p><p> private Double mORD_LToatal;</p><p></p><p> public Double MORD_LToatal</p><p> {</p><p> get { return mORD_LToatal; }</p><p> set { mORD_LToatal = value; }</p><p> }</p><p></p><p> public Boolean AddOrder(ORD_Class ordObj)</p><p> {</p><p> SqlConnection conn = new SqlConnection(connection);</p><p> string sql = "INSERT INTO ORD_DATA (ORD_NO, ORD_ID, ORD_Date, CUS_Name, CUS_Address, CUS_Contact, PRO_Code, PRO_Name, PRO_Des, PRO_Price, PRO_Qty, ORD_LTotal) values (@ORD_NO1, @ORD_ID2, @ORD_Date3, @CUS_Name4, @CUS_Address5, @CUS_Contact6, @PRO_Code7, @PRO_Name8, @PRO_Des9, @PRO_Price10, @PRO_Qty11, @ORD_LTotal12)";</p><p> conn.Open();</p><p> SqlCommand cmd = new SqlCommand(sql, conn);</p><p> cmd.Parameters.AddWithValue("@ORD_NO1", ordObj.mORD_NO);</p><p> cmd.Parameters.AddWithValue("@ORD_ID2", ordObj.mORD_ID);</p><p> cmd.Parameters.AddWithValue("@ORD_Date3", ordObj.mORD_Date);</p><p> cmd.Parameters.AddWithValue("@CUS_Name4", ordObj.mCUS_Name);</p><p> cmd.Parameters.AddWithValue("@CUS_Address5", ordObj.mCUS_Address);</p><p> cmd.Parameters.AddWithValue("@CUS_Contact6", ordObj.mCUS_Contact);</p><p> cmd.Parameters.AddWithValue("@PRO_Code7", ordObj.mPRO_Code);</p><p> cmd.Parameters.AddWithValue("@PRO_Name8", ordObj.mPRO_Name);</p><p> cmd.Parameters.AddWithValue("@PRO_Des9", ordObj.mPRO_Des);</p><p> cmd.Parameters.AddWithValue("@PRO_Price10", ordObj.mPRO_Price);</p><p> cmd.Parameters.AddWithValue("@PRO_Qty11", ordObj.mPRO_Qty);</p><p> cmd.Parameters.AddWithValue("@ORD_LTotal12", ordObj.mORD_LToatal);</p><p></p><p></p><p> try</p><p> {</p><p> cmd.ExecuteNonQuery();</p><p> conn.Close();</p><p> return true;</p><p></p><p> }</p><p> catch (Exception ex)</p><p> {</p><p></p><p> return false;</p><p> }</p><p> }</p><p></p><p></p><p> public List<ORD_Class> AllOrders()</p><p> {</p><p> List<ORD_Class> ordList = new List<ORD_Class>();</p><p> SqlConnection conn = new SqlConnection(connection);</p><p> string sql = "select * from ORD_DATA";</p><p> conn.Open();</p><p> SqlCommand cmdd = new SqlCommand(sql, conn);</p><p></p><p></p><p></p><p> try</p><p> {</p><p> SqlDataReader dr = cmdd.ExecuteReader();</p><p> while (dr.Read())</p><p> {</p><p> ORD_Class ordObj = new ORD_Class();</p><p> ordObj.mORD_NO = Convert.ToInt32(dr["ORD_NO"]);</p><p> ordList.Add(ordObj);</p><p></p><p> }</p><p></p><p> dr.Close();</p><p> return ordList;</p><p> }</p><p></p><p></p><p> finally</p><p> {</p><p> conn.Close();</p><p> }</p><p> }</p><p></p><p></p><p> }</p><p>}</p><p>[/CODE]</p><p></p><p></p><p>[CODE]public void saveODR()</p><p> {</p><p></p><p> {</p><p> if (txtCUSName.Text == "")</p><p> {</p><p> MessageBox.Show("Please enter the customer name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);</p><p> }</p><p> else if (txtCUSAddress.Text == "")</p><p> {</p><p> MessageBox.Show("Please enter the customer address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);</p><p> }</p><p> else if (txtCUSCON.Text == "")</p><p> {</p><p> MessageBox.Show("Please enter the customer contact number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);</p><p> }</p><p> else</p><p> {</p><p> try</p><p> {</p><p></p><p></p><p> ORD_Class ordObj = new ORD_Class();</p><p></p><p></p><p></p><p> ordObj.MORD_NO = Convert.ToInt32(lblORDNO.Text);</p><p> ordObj.MORD_ID = lblORDID.Text;</p><p> ordObj.MORD_Date = Convert.ToDateTime(lblDT.Text);</p><p> ordObj.MCUS_Name = txtCUSName.Text;</p><p> ordObj.MCUS_Address = txtCUSAddress.Text;</p><p> ordObj.MCUS_Contact = txtCUSCON.Text;</p><p></p><p> </p><p> for (int i = 0; i < dataGridView1.Rows.Count; ++i)</p><p> {</p><p> ordObj.MPRO_Code = Convert.ToString(dataGridView1.Rows[i].Cells[0].Value);</p><p> ordObj.MPRO_Name = Convert.ToString(dataGridView1.Rows[i].Cells[1].Value);</p><p> ordObj.MPRO_Des = Convert.ToString(dataGridView1.Rows[i].Cells[2].Value);</p><p> ordObj.MPRO_Price = Convert.ToDouble(dataGridView1.Rows[i].Cells[3].Value);</p><p> ordObj.MPRO_Qty = Convert.ToInt32(dataGridView1.Rows[i].Cells[4].Value);</p><p> ordObj.MORD_LToatal = Convert.ToDouble(dataGridView1.Rows[i].Cells[5].Value);</p><p> }</p><p> ordObj.MORD_Date = Convert.ToDateTime(lblDT.Text);</p><p></p><p></p><p> Boolean result = ordObj.AddOrder(ordObj);</p><p></p><p> if (result)</p><p> {</p><p></p><p> int value;</p><p> for (value = 0; value != 100; value++)</p><p> {</p><p> toolStripProgressBar1.Value = toolStripProgressBar1.Value + 1;</p><p> }</p><p> MessageBox.Show("Order successfully added to the Database.!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);</p><p> toolStripProgressBar1.Value = 0;</p><p> }</p><p> }</p><p> catch (Exception ex)</p><p> {</p><p></p><p> MessageBox.Show("Error in adding to the Database.!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);</p><p></p><p> }</p><p></p><p> }</p><p> }</p><p> }[/CODE]</p><p></p><p>[CODE]private void Cashire_Load(object sender, EventArgs e)</p><p> {</p><p> getORDCODE();</p><p> getORDNO();</p><p></p><p></p><p> UpdateTime();</p><p> timer.Enabled = true;</p><p></p><p> DataTable = new DataTable();</p><p> DataTable.TableName = "ORD";</p><p> DataTable.Columns.Add("CODE");</p><p> DataTable.Columns.Add("Name");</p><p> DataTable.Columns.Add("Description");</p><p> DataTable.Columns.Add("Price");</p><p> DataTable.Columns.Add("Quantiry");</p><p> DataTable.Columns.Add("Total");</p><p> rowCount = -1;</p><p></p><p> btnOK.Enabled = false;</p><p> txtQ.Enabled = false;</p><p></p><p></p><p></p><p> </p><p> }</p><p></p><p></p><p> public void LOAD() {</p><p></p><p> if (lblTotal.Text != "")</p><p> {</p><p></p><p> int a = dataGridView1.Rows.Add();</p><p> ++rowCount;</p><p> dataGridView1.Rows[rowCount].Cells[0].Value = lblPCODE.Text;</p><p> dataGridView1.Rows[rowCount].Cells[1].Value = lblName.Text;</p><p> dataGridView1.Rows[rowCount].Cells[2].Value = lblDes.Text;</p><p> dataGridView1.Rows[rowCount].Cells[3].Value = lblPrice.Text;</p><p> dataGridView1.Rows[rowCount].Cells[4].Value = txtQ.Text;</p><p> dataGridView1.Rows[rowCount].Cells[5].Value = lblTotal.Text;</p><p> }</p><p> else {</p><p> MessageBox.Show("SSS");</p><p> }</p><p> </p><p> }[/CODE]</p></blockquote><p></p>
[QUOTE="BoraluGoda, post: 13891337, member: 332053"] [SIZE="3"]මචංල දන්න කෙනෙක් මට කියල දෙනවද datagridview එක rows තියන data බට්න් ක්ලික් ඉවෙන්ට් එකකදී database එකට සේව් කරගන්න විදිය. මම datagridview එකට ගන්නෙ data table එකකින්. පහල තියෙන්නෙ මම කරපු codes.[/SIZE] [CODE]using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; namespace Billing_App { public class ORD_Class { String connection = "Data Source=CHANAKA-PC;Initial Catalog=Billing_System_DB;Integrated Security=True"; private int mORD_NO; public int MORD_NO { get { return mORD_NO; } set { mORD_NO = value; } } private String mORD_ID; public String MORD_ID { get { return mORD_ID; } set { mORD_ID = value; } } private DateTime mORD_Date; public DateTime MORD_Date { get { return mORD_Date; } set { mORD_Date = value; } } private String mCUS_Name; public String MCUS_Name { get { return mCUS_Name; } set { mCUS_Name = value; } } private String mCUS_Address; public String MCUS_Address { get { return mCUS_Address; } set { mCUS_Address = value; } } private String mCUS_Contact; public String MCUS_Contact { get { return mCUS_Contact; } set { mCUS_Contact = value; } } private String mPRO_Code; public String MPRO_Code { get { return mPRO_Code; } set { mPRO_Code = value; } } private String mPRO_Name; public String MPRO_Name { get { return mPRO_Name; } set { mPRO_Name = value; } } private String mPRO_Des; public String MPRO_Des { get { return mPRO_Des; } set { mPRO_Des = value; } } private Double mPRO_Price; public Double MPRO_Price { get { return mPRO_Price; } set { mPRO_Price = value; } } private int mPRO_Qty; public int MPRO_Qty { get { return mPRO_Qty; } set { mPRO_Qty = value; } } private Double mORD_LToatal; public Double MORD_LToatal { get { return mORD_LToatal; } set { mORD_LToatal = value; } } public Boolean AddOrder(ORD_Class ordObj) { SqlConnection conn = new SqlConnection(connection); string sql = "INSERT INTO ORD_DATA (ORD_NO, ORD_ID, ORD_Date, CUS_Name, CUS_Address, CUS_Contact, PRO_Code, PRO_Name, PRO_Des, PRO_Price, PRO_Qty, ORD_LTotal) values (@ORD_NO1, @ORD_ID2, @ORD_Date3, @CUS_Name4, @CUS_Address5, @CUS_Contact6, @PRO_Code7, @PRO_Name8, @PRO_Des9, @PRO_Price10, @PRO_Qty11, @ORD_LTotal12)"; conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@ORD_NO1", ordObj.mORD_NO); cmd.Parameters.AddWithValue("@ORD_ID2", ordObj.mORD_ID); cmd.Parameters.AddWithValue("@ORD_Date3", ordObj.mORD_Date); cmd.Parameters.AddWithValue("@CUS_Name4", ordObj.mCUS_Name); cmd.Parameters.AddWithValue("@CUS_Address5", ordObj.mCUS_Address); cmd.Parameters.AddWithValue("@CUS_Contact6", ordObj.mCUS_Contact); cmd.Parameters.AddWithValue("@PRO_Code7", ordObj.mPRO_Code); cmd.Parameters.AddWithValue("@PRO_Name8", ordObj.mPRO_Name); cmd.Parameters.AddWithValue("@PRO_Des9", ordObj.mPRO_Des); cmd.Parameters.AddWithValue("@PRO_Price10", ordObj.mPRO_Price); cmd.Parameters.AddWithValue("@PRO_Qty11", ordObj.mPRO_Qty); cmd.Parameters.AddWithValue("@ORD_LTotal12", ordObj.mORD_LToatal); try { cmd.ExecuteNonQuery(); conn.Close(); return true; } catch (Exception ex) { return false; } } public List<ORD_Class> AllOrders() { List<ORD_Class> ordList = new List<ORD_Class>(); SqlConnection conn = new SqlConnection(connection); string sql = "select * from ORD_DATA"; conn.Open(); SqlCommand cmdd = new SqlCommand(sql, conn); try { SqlDataReader dr = cmdd.ExecuteReader(); while (dr.Read()) { ORD_Class ordObj = new ORD_Class(); ordObj.mORD_NO = Convert.ToInt32(dr["ORD_NO"]); ordList.Add(ordObj); } dr.Close(); return ordList; } finally { conn.Close(); } } } } [/CODE] [CODE]public void saveODR() { { if (txtCUSName.Text == "") { MessageBox.Show("Please enter the customer name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtCUSAddress.Text == "") { MessageBox.Show("Please enter the customer address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtCUSCON.Text == "") { MessageBox.Show("Please enter the customer contact number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { ORD_Class ordObj = new ORD_Class(); ordObj.MORD_NO = Convert.ToInt32(lblORDNO.Text); ordObj.MORD_ID = lblORDID.Text; ordObj.MORD_Date = Convert.ToDateTime(lblDT.Text); ordObj.MCUS_Name = txtCUSName.Text; ordObj.MCUS_Address = txtCUSAddress.Text; ordObj.MCUS_Contact = txtCUSCON.Text; for (int i = 0; i < dataGridView1.Rows.Count; ++i) { ordObj.MPRO_Code = Convert.ToString(dataGridView1.Rows[i].Cells[0].Value); ordObj.MPRO_Name = Convert.ToString(dataGridView1.Rows[i].Cells[1].Value); ordObj.MPRO_Des = Convert.ToString(dataGridView1.Rows[i].Cells[2].Value); ordObj.MPRO_Price = Convert.ToDouble(dataGridView1.Rows[i].Cells[3].Value); ordObj.MPRO_Qty = Convert.ToInt32(dataGridView1.Rows[i].Cells[4].Value); ordObj.MORD_LToatal = Convert.ToDouble(dataGridView1.Rows[i].Cells[5].Value); } ordObj.MORD_Date = Convert.ToDateTime(lblDT.Text); Boolean result = ordObj.AddOrder(ordObj); if (result) { int value; for (value = 0; value != 100; value++) { toolStripProgressBar1.Value = toolStripProgressBar1.Value + 1; } MessageBox.Show("Order successfully added to the Database.!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); toolStripProgressBar1.Value = 0; } } catch (Exception ex) { MessageBox.Show("Error in adding to the Database.!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }[/CODE] [CODE]private void Cashire_Load(object sender, EventArgs e) { getORDCODE(); getORDNO(); UpdateTime(); timer.Enabled = true; DataTable = new DataTable(); DataTable.TableName = "ORD"; DataTable.Columns.Add("CODE"); DataTable.Columns.Add("Name"); DataTable.Columns.Add("Description"); DataTable.Columns.Add("Price"); DataTable.Columns.Add("Quantiry"); DataTable.Columns.Add("Total"); rowCount = -1; btnOK.Enabled = false; txtQ.Enabled = false; } public void LOAD() { if (lblTotal.Text != "") { int a = dataGridView1.Rows.Add(); ++rowCount; dataGridView1.Rows[rowCount].Cells[0].Value = lblPCODE.Text; dataGridView1.Rows[rowCount].Cells[1].Value = lblName.Text; dataGridView1.Rows[rowCount].Cells[2].Value = lblDes.Text; dataGridView1.Rows[rowCount].Cells[3].Value = lblPrice.Text; dataGridView1.Rows[rowCount].Cells[4].Value = txtQ.Text; dataGridView1.Rows[rowCount].Cells[5].Value = lblTotal.Text; } else { MessageBox.Show("SSS"); } }[/CODE] [/QUOTE]
Insert quotes…
Verification
Haya warak paha keeyada? (haya wadi kireema paha)
Post reply
Top
Bottom