Data Grid View的数据存到数据库

今天有个需求,将Data Grid View的数据导入到数据库中

操作思路

        将Data Grid View按照每行分开,然后获取每行的每个单元格,使用SQL语句存到数据库中。既然思路清晰了,那么我们再来研究一下如果将Data Grid View每行都分开,Data Grid View自带一个获取每行值的叫做DataGridViewRow,下面就是使用DataGridViewRow 的演示代码。

DataGridViewRow row in dataGridView1.Rows

 算了,直接上例子吧,太简单,没啥写的

if (dataGridView1 != null)
                {
                    int Num = 0;
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        Num++;//计算数据数
                        //获取每行的每个单元格值
                        string PlanID = row.Cells[1].Value?.ToString();
                        string DeviceID = row.Cells[2].Value?.ToString();
                        string MaterialID = row.Cells[3].Value?.ToString();
                        string ProductID = row.Cells[4].Value?.ToString();
                        string MaterialCode = row.Cells[5].Value?.ToString();
                        string ProductIDSmall = row.Cells[6].Value?.ToString();
                        //判断获取的值是否为空,为导入做准备,如果为空不记录
                        if (string.IsNullOrEmpty(PlanID) || string.IsNullOrEmpty(DeviceID) || string.IsNullOrEmpty(MaterialCode) || string.IsNullOrEmpty(ProductID) || string.IsNullOrEmpty(MaterialID) || string.IsNullOrEmpty(ProductIDSmall))
                        {
                            continue;
                        }
                        // MessageBox.Show(PlanID + productCode + productID + DeviceID + productIDSmall + MaterialID);
                        //存入数据库,
                        string Str = "insert into tb_Materialcode(PlanID,DiviceID,ProductID,MaterialID,Materialcode,ST,Count,FramecCode,Size,ProductIDSmall)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')";
                        Str = string.Format(Str, PlanID, DeviceID, ProductID, MaterialID, MaterialCode, 0, 0, null, 0, ProductIDSmall);
                        if (SQLHelper.ExecuteNoQuery(Str) > 0)
                        {
                            MessageBox.Show("第" + Num + "条数据成功录入");
                        }
                    }
                }

                        //ExecuteNoQuery代码
                        public static int ExecuteNoQuery(string cmdText)
                        {
                            using (SqlConnection sqlConn = new SqlConnection(connString))
                           {
                                sqlConn.Open();
                                SqlCommand sqlCommand = new SqlCommand(cmdText, sqlConn);
                                int rows = sqlCommand.ExecuteNonQuery();
                                if (rows <= 0)
                                {
                                    LogHelper.Monitor(cmdText + "\r\n" + "操作数据库失败!");
                                }

                                return rows;
                            }
                        }

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SQLite3 数据据管理工具 图形界面 SQLite Expert is a powerful visual tool that enables you to easily administer your SQLite3 databases and gain significantly better visibility into how your databases are operating. SQLite Expert integrates database management and maintenance into a single, seamless environment, with a clear and intuitive graphical user interface. Homepage: www.sqliteexpert.com Features include: 1. Modify table structure visually without losing data already existing in the database. SQLite Expert will automatically create a new table with the new structure and copy the data from the old table. All the operations are wrapped in a transaction which is rolled back if any error occurs during the process. 2. Build SQL scripts visually using the integrated Query Builder. 3. Create SQLite3 databases, view and change database parameters, check database integrity and vacuum (compact) database. 4. The Data Transfer Wizard allows import/export from/to SQL script, another SQLite database or an ADO data source. 5. Display and edit data in the grid, including BLOB and image fields. Currently supports BMP, JPG and PNG image formats. 6. BLOB fields can be edited with the integrated hex editor. 7. Execute SQL queries. Supports multiple SQL statements in the same query. 8. In-grid editing of live queries. 9. Save/Load SQL scripts to/from file. 10. Transaction support. SQLite supports one level of transactions. 11. Data mapping. SQLite Expert supports custom data types, and 40 predefined data types. 12. Extend and enhance SQLite Expert using Lua or Pascal scripts. System Requirements Operating System: Windows 2000/XP/2003/Vista SQLite - sqlite.dll version 3.x. (included)
1 , datafile.zip<br>"This sample demonstrates how to do file input and output using Visual Basic. The sample creates a new database file and allows you to view, add, or delete records in this database."<END><br>2 , dbprint.zip<br>This demonstrates how to print data from a database.<END><br>3 , edittbls.zip<br>This is an EXCELLENT example on how to edit database Tables through VB.<END><br>4 , graphdb.zip<br>This demonstrates how to graph information from a database to a picturebox.<END><br>5 , ClassBuilder1.zip<br>Class Builder - reads SQL Server or Access database and creates a class of the selected table<END><br>6 , adoView1.zip<br>ADO viewer. Retrieve all columns, querys and fields of a database and put them in a TreeView(using OpenSchema ADOConnection method)<END><br>7 , imagechunk1.zip<br>This application will save JPG,BMP,GIF files in your database and allows you to fetch the same. Code example for saving and fetching the same in oracle and sql is also given.<END><br>8 , DBImpExp.zip<br>A utility to import/export Access database from/to other application formats, e.g. Excel and text files. With sample files and help, as well as ample remarks.<END><br>9 , pb_test.zip<br>Test project illustrating high performance Data Access for SQL Server using ADO command objects and Stored Procedures for Insert, Update, Delete and Select. Two methods for Selects are shown <END><br>10 , Employees.zip<br>This is a database project, for storing employees data.<END><br>11 , DBProject2.zip<br>New version of DBProject. Allows you view, scroll through, and edit an access database. <END><br>12 , adoview.zip<br>ADO Viewer,This code retrieve all columns, querys, fields of a database(Access, SQL Server, etc...)<END><br>13 , Cheques2.zip<br>New version of Cheques program. Must see...<END><br>14 , ADOSQLcodeGenerator.zip<br>SQL and ADO Code Generator. Generate SQL statement and ADO Code Connection without the use of an ADO Data Control. <END><br>15 , client.zip<br>This application is about programming with Client Side Cursors. <END><br>16 , AccessSecurity.zip<br>An Access97 security tool. Replaces going into Access97 and switching between security forms. <END> <br>17 , DatabaseViewandEdit.zip<br>Do about anything with Access databases. View, edit, export contents to Word or Excel, etc., etc.<END><br>18 , VBSales.zip<br>This is a complete database program for sales which help you to create purchase order, Invoice, etc. <END><br>19 , accidents.zip<br>A programme meant to add, edit,delete,and searching data. It includes how to show statistics regarding the accidents information.just try it. It is handy in studying database programming.<END><br>20 , MySQLExplorer.zip<br>Explorer for MySQL Data Base.You can retrieve and execute your query. <END><br>21 , ICDBaseSource115.zip<br>DAO based database program with many features in it<END><br>22 , ICDBSourceBeta115.zip<br>teach people just beginning with databases and also i am new to databases so this is pretty well commented.<END><br>23 , Diary.zip<br>This application everything you need.t has a CALCULATOR.It has TIME & DATE u can even set the system time<END><br>24 , L_datab.zip<br>The functions are for open Databases including passwords, creating Recordsets , executing SQL statements, renaming tables and many more.<END><br>25 , CodeGen.zip<br>VB code generator,The application currently generates data classes for Access '97 databases. <END><br>26 , dbexample.zip<br>The best part about using a MS JETDB EnGINE4 is that the DB can be accessed through a network. <END><br>27 , ComboLookup.zip<br>Zip Code Database Is A Program To Find Zip Codes By Using A Lookup Field. <END><br>28 , UDL.zip<br>This is a class that lets you create and edit UDL files<END><br>29 , qbd-dbCoder131.zip<br>This code shows how to take data from a VB database application and place it into an Excel spreadsheet.<END><br>30 , Family_v2_upload_Apr_05_2000.zip<br>This is a family address book program created using VB6. <END><br>31 , datsearch.zip<br>Application which searches an Access database for a specified search term entered by the user.<END><br>32 , DBTextGrid.zip<br>This program is the modification of my previous Textgrid.Now you can Add, Modify, Delete, View, Save data to/from your database with this Grid. The grid was formed with array of text boxes.<END><br>33,txtgrid.zip<br>This program creates text box array dynamically and loads the database fields onto it. <END><br>34,DAOLike.zip<br>This program Demonstrates how to use LIKE operator in Jet SQL Query (uses DAO).<END><br>35,xmlcreator.zip<br>This project is a demonstration of how to convert a recordset into an XML format file. Its well documented and more XML stuff to come along.<END><br>36,compmdb.zip<br>This program will allow the user to select a MDB file to compact. Its then backed up just in case, compressed and then the original is deleted before the new compacted version is moved back in place of the original.<END><br>37,dbinfo.zip<br>We've written this mainly for when we develop databases, but really you could adapt it for productive use too. By supplying a DSN entry, it will attempt to connect to that database and list all the tables in it. When you click on a table, it lists all <END><br>38,3a.zip<br>An Inventory System, you can add, edit, sort, find, delete, print, change your password and create a backup of your database<END><br>39,A417Source.zip<br>Full original RANDOM DATA INDEXING (SY-32)METHOD),Faster DATA access than a classical database application. the 1st source of new indexing method (SY-32) <END><br>40,student.zip<br>This is Student Administration Project , u can administrate student through this programme in any institute when u run the programme please use password "mars3" then u can run please check it. <END><br>41,ADOViewer.zip<br>ADO DataBase Viewer. Can open multiple concurrent databases from seperate providers. Works with Access, SQL Server and DSN. I included the ODBC Logon from VB6 so it should be able to hook up to any data provider that supports ADO. <END><br>42,rptparam.zip<br>Passing parameters with data reports. I have set two parameters and passed them during run time.Open with VB6. <END><br>43,CompactRepair.zip<br>A small application that shows you how to compact and repair a Microsoft Access mdb or mde using ADO (JRO). <END><br>44,Ledgerinvb5.zip<br>This is simple GL ledger Project, again a database program. It has an interesting part if you click About button. Must see it. <END><br>45,AdoSort.zip<br>Ado Data Sort Control will display your data from database, filter, sort (up to 3 levels) all in HFlexGrid!!! <END><br>46,adoxml.zip<br>Use ADO to convert database records into an XML file. All users must have MSXML.dll version 3.0, and Internet Explorer 5.5. <END><br>47,DataCntl.zip<br>Simple application that shows how to use the Data Control to connect to the Biblio.mdb database and display all authors in the Authors table. <END><br>48,MyTool.zip<br>An SQL Query tool for SQL Server or Oracle. <END><br>49,fab15.zip<br>Complete Database Address book With Lots Of New Facilites.....下载 Now. <END><br>50,DataBaseViewer.zip<br>DataBase Viewer is a program that lets you to look at your database files. It opens the recordsets in a table for easy viewing and also has a percents and progress bar to show the exact loading progress of the RecordSet. <END><br>51,Dynarep.zip<br>This program generates a dynamic datareport during runtime without using any DataEnvironment object. I have passed the datasource and recordset properties during run time. Opens with VB6.<br><END><br>52,EditUDL2.zip<br>This is a newer version of the Edit UDL class. This version 2.3 enables you to Create, Edit and Save UDL files either by the UDL properties Dialog Box or by a connection string. The class adds some additional Properties. The Zip file contains not only the class but a sample project demonstrating the use of the UDL class. <END><br>53,ADOclient-side.zip<br>In a network environment, open a connection to a database, retrieve data, close the connection, work with the data, reopen the connection to communicate with the database again and do a batch update. <END><br>54,udl2.zip<br>This application reads universal data link files from disk, creates them, and saves modifications to them to a file. UDL files contain ADO connection information to data sources. Their output can be used as a connection string in your applications. <END><br>55,timebilling.zip<br>This is a full 3-tier dababase application which includes a activex dll project(business objects) and a standard exe(UI). <END><br>56,ADODAOpw.zip<br>Application which shows how to access a password protected Access database using DAO and ADO. <END><br>57,DBExplorer.zip<br>Database explorer for viewing all tables and queries in a database. Also includes an SQL editor similar to SQL Query Analyzer. <END><br>58,FriendsDb.zip<br>ADO Database, Improved login and made the program smaller but with the same options as before just a few extra ones with the login such as write the login to the registry instead of just to a ini file also better encryption for the ini file... Now you can save your password as a number, in the previous login the encryption was poor. <END><br>59,FriendsDb105.zip<br>ADO Database... FriendsDatabase Version 1.05 ... Updated Again, Added even more error handling and images to the listview box also added a few forms to stay on top. Some major error additions i skipped before, runs much smoother now not that it didn't before. <END><br>60,Friends.zip<br>GREATLY UPDATED: Added much better error handling just to be safer and more neat... Also added more sound so all commands have a sound and upon loading a 3 second wav plays also included is the advanced progress bar and ocx that i found in someone elses source that is great for multiple reasons.. <END><br>61,FriendsDatabase.zip<br>My first ADO database, i learned from tutorials on here specifically from Jerry Barnes so i think this would be great for people new to ADO databases to learn from but i suggest finding Jerry Barnes ADO For beginners source because it is incredibly commented on and will surely have you creating ADO within 20 minutes. <END><br>62,user_query.zip<br>The Application basically allows you to connect to any Access Database view records of each table, along with the table design ,write sql statements on the fly(any dml statement).Most Of The Functionality Of The Application Has Been Automated. A must See.. <END><br>63,Database.zip<br>Database application. Must see... <END><br>64,Cheque.zip<br>Cheques. Must see... <END><br>65,ICDBaseSource.zip<br>DAO based database program with many features in it, I also noticed after searching around I seen no databases that supported saving gaming info so I made one witht he ability for saving game info such as favorite game, gaming handle, clan name, clan rank... <END><br>66,pizza.zip<br>Pizza Program. Must see... <END><br>67,prjDataEnv.zip<br>This VB database application shows how to use DataEnvironment in code. <END><br>68,Familyv3.zip<br>This is new version of a family address book that I released some time ago. This time around I mostly use ADO instead of DAO and now the user isallowed to add or remove any category of their choice. <END><br>69,AgendaRBC.zip<br>An Agenda which uses a text database file. <END><br>70,project26.zip<br>Stocks Portfolio. <END><br>71,vbasics.zip<br>This is a database project that uses the VB DBGrid control to display and scroll through all records in an Access database. <END><br>72,vbWales.zip<br>Database app. I did as a college assignment. Only simple stuff but there is some good tab strip code etc... <END><br>73,DBProject.zip<br>Database Viewer application. Allows you to view and scroll through all of the records in a database. <END><br>74,dbCoder.zip<br>Access97 Database Coder. Analyses a database and writes the code required to create blank copy. Two projects dbCoderAddIn.vbp can be compiled as an add-in and will place the code in a new module of the active project. <END><br>75,move_vb6.zip<br>Demonstrates how to use the data control to move through a recordset. <END><br>76,ado.zip<br>Opens an access database using ADO and then displays all records, provider properties and error information in a list box. <END><br>77,f_119.zip<br>An example of a bound form using the ADO control(4KB)<END><br>78,f_118.zip<br>Examples of a connectionless recordset(2KB)<END>
Navicat Premium是一个数据库开发工具,可让您从单个应用程序同时连接到MySQL,MariaDB,MongoDB,SQL Server,Oracle,PostgreSQL和SQLite数据库。与Amazon RDS,Amazon Aurora,Amazon Redshift,Microsoft Azure,Oracle Cloud,Google Cloud和MongoDB Atlas等云数据库兼容。您可以快速轻松地构建,管理和维护数据库。 设置数据源连接后,可以使用“导入向导”将数据从多种格式或从ODBC传输到数据库。将数据从表/集合,视图或查询结果导出为Excel,Access,CSV等格式。使用我们的内置编辑器添加,修改和删除记录,您可以在Tree View,JSON View和类似电子表格的经典Grid View方便地进行编辑。Navicat为您提供有效管理数据并确保流程平稳所需的工具。 Visual SQL / Query Builder将帮助您创建,编辑和运行SQL语句/查询,而不必担心语法和命令的正确用法。通过获取关键字建议并从编码去除重复内容,使用“代码完成”和可自定义的代码段快速进行编码。使用我们的调试组件,例如设置断点,单步执行程序,查看和修改变量值以及检查调用堆栈,可以快速找到并纠正PL / SQL和PL / PGSQL编码错误。 使用我们专业的对象设计器创建,修改和管理所有数据库对象。使用复杂的数据库设计和建模工具将数据库转换为图形表示形式,以便您可以轻松地建模,创建和理解复杂的数据库。 我们的图表功能使您可以创建大型数据集的可视表示形式,并帮助您从数据获得更深刻的见解。探索并发掘数据之间的模式,趋势和关系,并创建有效的视觉输出,以将您的发现显示在仪表板上以进行共享。 我们功能强大的本地备份/还原解决方案以及针对MongoDump,Oracle Data Pump和SQL Server Backup Utility的直观GUI,可指导您完成备份过程并减少潜在的错误。为可重复部署的过程设置自动化,例如在特定时间或日期执行数据库备份,MapReduce作业和脚本执行。无论您身在何处,都可以随时完成工作。 使用我们的内置模式可视化工具发现和探索您的MongoDB模式。分析文档并在集合显示丰富的结构,以便您可以了解数据的架构,查找架构异常并轻松检查异常值。 通过SSH隧道和SSL建立安全连接,可确保每个连接都是安全,稳定和可靠的。支持不同的数据库服务器身份验证方法,例如MySQL和MariaDB的PAM身份验证,MongoDB的Kerberos和X.509身份验证以及PostgreSQL的GSSAPI身份验证。Navicat提供了更多的身份验证机制和高性能环境,因此您不必担心通过不安全的网络进行连接。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值