473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Database and datagrid

2
Expand|Select|Wrap|Line Numbers
  1. private void btnSaveinDB_Click_1(object sender, EventArgs e)
  2.         {
  3.             if (conn.State == ConnectionState.Open)
  4.             {
  5.                 conn.Close();
  6.             }
  7.  
  8.             try
  9.             {
  10.              int i = 0;
  11.              if (dgvfareaudit.Rows[i].Cells[2].Value == DBNull.Value)
  12.                 {
  13.                   MessageBox.Show("Datagrid is empty!");
  14.                 }
  15.  
  16.                 dap.InsertCommand = new SqlCommand("INSERT INTO dbo.fare_table(fromsector,sectorto,farebasis) VALUES('" +
  17.                 dgvfareaudit.Rows[i].Cells["fromsector"].Value.ToString() + "','" +
  18.                 dgvfareaudit.Rows[i].Cells["sectorto"].Value.ToString() + "','" +
  19.                 dgvfareaudit.Rows[i].Cells["farebasis"].Value.ToString() + "','" +
  20.                 dgvfareaudit.Rows[i].Cells["owrt"].Value.ToString() + "','" +
  21.                 dgvfareaudit.Rows[i].Cells["currencycode"].Value.ToString() + "','" +
  22.                 dgvfareaudit.Rows[i].Cells["lcf"].Value.ToString() + "','" +
  23.                 dgvfareaudit.Rows[i].Cells["nuc"].Value.ToString() + "','" +
  24.                 dgvfareaudit.Rows[i].Cells["carriercode"].Value.ToString() + "','" +
  25.                 dgvfareaudit.Rows[i].Cells["rule"].Value.ToString() + "','" +
  26.                 dgvfareaudit.Rows[i].Cells["mpm"].Value.ToString() + "','" +
  27.                 dgvfareaudit.Rows[i].Cells["gi"].Value.ToString() + "','" +
  28.                 dgvfareaudit.Rows[i].Cells["frbd"].Value.ToString() + "','" +
  29.                 dgvfareaudit.Rows[i].Cells["svf"].Value.ToString() + "','" +
  30.                 dgvfareaudit.Rows[i].Cells["svt"].Value.ToString() + "','" +
  31.                 dgvfareaudit.Rows[i].Cells["fvf"].Value.ToString() + "','" +
  32.                 dgvfareaudit.Rows[i].Cells["fvt"].Value.ToString() + "','" +
  33.                 dgvfareaudit.Rows[i].Cells["primecode"].Value.ToString() + "','" +
  34.                 dgvfareaudit.Rows[i].Cells["seasonalcode"].Value.ToString() + "','" +
  35.                 dgvfareaudit.Rows[i].Cells["pow"].Value.ToString() + "','" +
  36.                 dgvfareaudit.Rows[i].Cells["pod"].Value.ToString() + "','" +
  37.                 dgvfareaudit.Rows[i].Cells["fptc"].Value.ToString() + "','" +
  38.                 dgvfareaudit.Rows[i].Cells["fli"].Value.ToString() + "')",conn);
  39.                 //}
  40.                 conn.Open();
  41.                 //dap.InsertCommand.Connection = conn;
  42.                 ////dap.InsertCommand.CommandText = SqlSelect;
  43.                 //dap.InsertCommand.CommandTimeout = 0;
  44.                 //dap.InsertCommand = new SqlCommand(SqlSelect, conn);
  45.                 dap.InsertCommand.ExecuteNonQuery();
  46.                 MessageBox.Show("Record Successfully Saved", "Symphony", MessageBoxButtons.OK, MessageBoxIcon.Information);
  47.  
  48.  
  49.                 conn.Close();
  50.  
  51.  
  52.  
  53.             }
  54.             catch (Exception ex)
  55.             {
  56.                 MessageBox.Show(ex.Message);
  57.             }
  58.             finally
  59.             {
  60.                 conn.Close();
  61.             }
  62.         }
Mar 27 '14 #1
1 1284
rody9
2
In fact I want to know how to save data from datagrid to database
Mar 27 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Gamze | last post by:
Hi, How can i get values from datagrid to combobox and should select the same name as in datagrid row on the combobox control In my vb.net windows application ,i have combobox which is...
0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
0
by: aftab | last post by:
I have two fetch records from two different database that is from Sqlserver and oracle and give as a datasource to a single Datagrid control. how can i do it? Aftab
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
3
by: mattdaddym | last post by:
Hi all, I have been using the following code to export my datagrids to excel for quite some time. Very simple and very effective. <code> Sub btnExcelExport_Click ( s As Object, e As...
4
by: cooltech77 | last post by:
Hi, I am trying to build the following functionality in the datagrid. I have a lot of columns in the datagrid which are being populated from the database and the user needs to scroll...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.