I'm sure I've mentioned this type of wrapper class for accessing databases in a provider-agnostic manner before, but never posted a functional implementation. So here it is. Questions, comments, and suggestions are welcome as always. :)

Member Avatar
Member Avatar
+3 forum 4

This code snippet demonstrates how to use ADO.NET to read the contents of a Microsoft Excel Worksheet. This snippet also demonstrates the use of the [GetSchema](https://msdn.microsoft.com/en-us/library/ms135981%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396) method to determine what worksheets are available within an Excel workbook allowing the end user the ability to select a specific worksheet in order to view the data. To start, create a Windows Forms application and add the following controls so that it resembles the screenshot below: ![excelDataGridView.JPG](/attachments/small/4/399358612891345b370abe864f618d01.JPG) * Label (Name: excelFileLabel, Text: Excel File) * Text Box (Name: excelFileTextBox, Anchor: Top, Left, Right) * Button (Name: openFileButton, Text: ..., Anchor: Top, Right) * …

Member Avatar
Member Avatar
+2 forum 6

I have created an MS Access Query named **GetContactCategory** select GetCategoryNames(contactId) as CategoryNames from Contacts The Function **GetCategoryNames** is the function written in a module of same database. Now when i call this query in my c# application using ADO.net it throws error. Following is my c# code ` using (OleDbCommand cm = new OleDbCommand()) { cm.Connection = AccessConnection(); cm.CommandType = CommandType.StoredProcedure; cm.CommandText = "GetContactCategory"; cm.Connection.Open(); using (OleDbDataReader reader = cm.ExecuteReader())//This line throws error { //some code } } ` The error which is get Undefined function '**GetCategoryNames**' in expression. what is the problem and whats the solution.

Member Avatar
Member Avatar
+0 forum 1

hey all, i have a little issue here with the below however the wired thing that i encoutred is that the below code run only for one time perfectly and when i invoked it again it displayes the error : " The ConnectionString property has not been initialized. " private void Label1_TextChanged(object sender, EventArgs e) { // the below Snippet is for Searching the database Access and Retirving it in the database if (Label2.Text == "EDIT") { using (AMSCONN) { string UpdateString = "SELECT EmpCode,EfCode,Branch,SectorName,EmpType,SuperVisor,EmpName,Govenment,District,Area,Email,addrs FROM AddressBook WHERE EmpCode = '" + ForSearch.Text + "'"; } AMSCONN.Open(); // here is …

Member Avatar
Member Avatar
+0 forum 2

I made an online application to store employees information in MS SQL,I used Disconnected model and I made my class for "DataSet configuration" and call method in it in The "Form_Load" event. This is the class public static string constr = ConfigurationManager.ConnectionStrings["cnn1"].ConnectionString; public static DataSet GetDataSet(string stored_name, string table_name, params SqlParameter[] prmarr) { SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(stored_name, con); foreach (SqlParameter prm in prmarr) { cmd.Parameters.Add(prm); } cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, table_name); return ds; I set the Connection string in "Web.Config" Till now all things …

Member Avatar
Member Avatar
+0 forum 2

I have developed a windows application. My development environment is win7, office2007, C#, VS2010, Winforms. My application stores data in MS Access. Is there any way with which i can create a connection string based on Oledb driver version present in PC?

Member Avatar
Member Avatar
+0 forum 1

Hello, I had a very peculiar problem today which I am sure hundreds would have had and solved before. I have developed a VB.Net + SQL Server application and installed it in a few dozen places. All worked very well. Then I installed it in a persons computer in Middle East in the City of Nablus. To my surprise, the app is not even reading user id and password.. The database is connected but just not fetching any data.. The Nablus installation obviously is having a English and Jordan(Arabic) interface and of course the person can easily change from English …

Member Avatar
Member Avatar
+0 forum 2

Hi I have a big (working) software written in C++ that uses SQL database, using the ADO interface. I'm currently using old ADO libraries (prior to the Windows7 SP1 problem) and wish to upgrade. I'm considering taking advantage of this need and upgrade to ADO.NET. What do you think?

Member Avatar
Member Avatar
+0 forum 1

HI All, I'm writing an application in Visual Basic .NET but the application will use a SQL backend. If the user runs the application and the backend database is not set up, I want the user to select a SQL Database Instance, supply an administrator user ID (sa) and Password and then the application will connect to the SQL Instance via ADO.NET and Create the Database. The app will then create a Database user for the application to use (so we don't have users using the Admin account,) and then create the Tables and Stored procedures in the database and …

Member Avatar
Member Avatar
+0 forum 2

I have a console application that I need to run a stored procedure in but I'm getting this error: a t S y s t e m . D a t a . S q l C l i e n t . S q l C o n n e c t i o n . P e r m i s s i o n D e m a n d ( ) a t S y s t e m . D a t a . S q l C l i e n t . S …

Member Avatar
Member Avatar
+0 forum 1

I have a bound datagridview and a dataset with tables. I have two sets of comboboxes bound to the same field "Restaurant" in the tables (mirroring each other). In the "NewEmployeeRestaurant" combobox I change the value and it reflects in the datagridview. I can shoot around clicking all over the datagridview on other employees, but when I return to the employee I changed, the value remains what I changed it to. All is good in the world. However, when I go to the "EmployeeRestaurant" combobox with the same settings, I change the value and it is reflected in the datagridview. …

Member Avatar
Member Avatar
+0 forum 4

Hi i have the following code. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim con As New OleDbConnection Dim da As New OleDbDataAdapter Dim ds As New DataSet Dim dsnewrow As DataRow Dim cb As New OleDbCommandBuilder(da) Dim a As String con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\DB.mdb;Jet OLEDB:Database Password=123" con.Open() a = "select * from Login" da = New OleDbDataAdapter(a, con) da.Fill(ds, "Login1") dsnewrow = ds.Tables("Login1").NewRow() ds.Tables("Login1").Rows.Add(dsnewrow) dsnewrow.Item("Lid") = "test" dsnewrow.Item("Name") = Uname2.Text.ToString() dsnewrow.Item("Lps") = psw1.Text.ToString() dsnewrow.Item("Acces1") = Acs.Text.ToString() dsnewrow.Item("Date1") = DTp1.Value.ToString() [COLOR="Red"]da.Update(ds, "Login1")[/COLOR] Uname2.Text = "" psw1.Text = "" Acs.Text = "" DTp1.Value = Today() con.Close() …

Member Avatar
Member Avatar
+0 forum 4

Hi daniweb first of all, sry my english. I have a problem with at update code, I was hoping that U can help me, im new to this. i have a code where i get an id from another page, from update.aspx?id=1 up to 6 ATM. my code works fine to get the record from my DB, from the id number (in this case 1) But when i then add my buttom.Click code, i get some not declared errors !? its the addwithvalue lines. Hope someone can help me and maybe guide me to a better solution on how to …

Member Avatar
Member Avatar
+0 forum 1

I have form where 4 buttons(Platinum, Diamond, Gold and Reset) are there, I have 3 Panel Control one for each of the first 3 buttons, what I want to do is that when I click on any one of the first three buttons the Panel for the respective buttons should appear on the screen and if any Panel is already on the screen it should not be visible. For e.g At any point of time when the application is running, consider that the Panel for the Platinum button is already on the screen and if I click on the Diamond …

Member Avatar
Member Avatar
+0 forum 7

I have added a panel control at the design time and I want to add some buttons in the panel at the runtime, the code for adding the buttons in working perfectly, but the problem is with the Panel control, when the Buttons are added at the run time, the Panel hides the buttons behind itself, can anyone suggest the solution, I am pasting the code from designer as well the code that I have written. Please correct my mistake. Code from Form3.Designer.cs: namespace rough2 { partial class Form3 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer …

Member Avatar
Member Avatar
+0 forum 2

I have a Windows Form where 225 buttons are added at the run time, also I have the database which have two columns (first column is the SeatNumber with the datatype nchar(4) and the other column is IsBooked with the datatype bit). The SeatNumber contains data like this, A1,A2,A3,A4................O13,O14,O15, The other column contains value either 0 or 1. What I want to do is that when the form loads it should check in the database which rows of the second column has the value 1, for e.g. If A1,A2,A3,A4 and B1,B2,B3,B4 has the value 1 the buttons with the same …

Member Avatar
Member Avatar
+0 forum 23

Hi there all, I am trying to get data from a sql view and bound it into the datagridview, after that, I add 4 more colums into the datagridview which are editable, finally pass the entered data into a new database and call that data in the future in the load of Datagridview... I have 19 colums return from view, 4 more colums I have added. Here is the code; [CODE]string[] kolon = { "Asd1", "Asd2", "Asd3", "Asd4" }; private void button1_Click(object sender, EventArgs e) { string ad; SqlConnection conn = new SqlConnection("Server=.;Database=CrmDatabase;Trusted_Connection=True"); for (int i = 0; i < …

Member Avatar
Member Avatar
+0 forum 5

Hi there all, First of all, I need to say that I'm so happy to join you... Second, I have a problem... First I created a form page with a constructor that fills the listbox in it... As you can imagine all stuff begins after filling it... However, a friend of mine said that it will be good to add a Tabcontrol into that form... I add it and "copy-paste" all the form controls in it... But now I cant access them, plus listbox is empty... :( Please help... TABCONTROL-FORM-ADO.NET stuff... [CODE] SqlDataAdapter cmd = new SqlDataAdapter("Select * From Ilgililer …

Member Avatar
Member Avatar
+0 forum 4

Hi Experts, I have a windows service running every minute and has many database operations to perform. It runs perfectly for many days, sometimes it suddenly stops and throws this exception. Later when we start to debug it, the exceptions goes off, but if we don't debug, the exception continues to come. We are tired of this totally random scenario. Please assist us with this. We are using sqlhelper.cs for database interaction. "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding." Best Regards, Wajid Ahmed Ansari.

Member Avatar
Member Avatar
+0 forum 5

I need a timer that will change the text of a combobox which is binded to a database. My Application which is based on hospital management wherein a doctor has to visit rooms within 6 hours. If 6 hours elapse the combo should show "need......" and if not something "......" and the changes should be also written in the database as there are many rooms. there should also be a button that resets the timer. please help me. Thank you so much

Member Avatar
Member Avatar
+0 forum 2

Im Writing a c# Code that Takes an Excel Sheet ,creates the Corresponding SQl table and Dumps the data in a new table in SQL. Now My problem is: In the " create table" command , i have to specify the DATATYPE for the column !i.e. CREATE TABLE "table_name" ("column 1" "data_type_for_column_1", "column 2" "data_type_for_column_2", ... ) So i wrote the following code that saves the Excel Column names in the strColumnNameArray (of type String) and their corresponding Data Types in the DataTypeArray (of type Type) [CODE] foreach (DataRow row in schemaTable.Rows) { strColumnNameArray[i] = ((string)row["ColumnName"]); DataTypeArray[i] = (Type)row["DataType"]; i++; …

Member Avatar
+0 forum 0

Dear Friends I have Developed a Successful Database Software, it include Datagrid, First, Last, Next, Previous, Add, Delete, Edit, Update, Search just Every Thing is Working Nice, But I need help from one of expert from you. my problem is that every time when i Start program its all functions are workin including edit and delete. (mean data (rows) Added at previous run is able to be Delted at current time) but when i add new record at current run time it adds succesfully, but while at same run time session (current) i tries to Delete or edit new added …

Member Avatar
Member Avatar
+0 forum 3

Hello sir, I have add one listbox in my code. i'm assigning data to the list box at runtime from DataSet. The Value member of the ListBox is EmployeeID and Display member of the ListBox is EmployeeName. [B][U]User Can Select Multiple EmployeeNames at Run time [/U][/B]. Now I want to send value member of the selected Items in the listbox to query for filteration How i should do Plz help me. I'm using code as below, for(int i=0; i < this.listAddNo.SelectedItems.Count; i++) { strItem2 = listAddNo.SelectedItems[i].ToString().Trim(); MessageBox.Show(strItem2); if (counter == 0) { ADDNO = strItem2; } else { ADDNO = …

Member Avatar
Member Avatar
+0 forum 1

I Want To Search Date From .mdb Database file, Table Name is Purchase, and The Field is Purchase Date, its Type is DateTime and Formate is ShortDate in MS Access Database File, I Conceted it to Vb.net Form, and Tryed to Search Date, but it Returns Error. the Code to Connect and Search Date Record is as Follows [CODE] Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click PurchaseConn.ConnectionString = "Provider=Microsoft.jet.oledb.4.0; Data Source=" & Pth & "\DisplayCenterData.mdb; User Id=admin; Password=;" 'pth is Variable for Project Folder's Path PurchaseSql = "Select * from PUrchase where PurchaseDate =" & …

Member Avatar
Member Avatar
+0 forum 4

My vb 2008 app uses Excel, but only briefly. Can I avoid referencing the Interop library Microsoft.Office.Interop,Excel?? Is there another way to link to Excel? In terms of its dealings with Excel, my app does little more than open a workbook and shade some cells. Many thanks

Member Avatar
Member Avatar
+0 forum 3

Friends I m working with RowFilter, its working good with String Data, and like statements, specially its Autometed functuallity with string data is good, just like in follwing code (it is written in Textbox "txtSearch"s TextChanged Event) [CODE] Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged PurchaseDt.DefaultView.RowFilter = "salePerson like '" & txtSearch.Text & "%'" End Sub [/CODE] this is working good, it search saleperson field in datatable (purchaseDt in my case) as we type text, if we remove text from textbox (txtSearch) then it shows all Rows data from database, same is not with Integer, …

Member Avatar
Member Avatar
+0 forum 3

I have created simple database project, using vb.net, ado.net, oledb, datatable, datagridview. My program is working nice, I just need Help with how to add, delete, update and edit records. Can any one please and please help me in this case, or can provide any good tutorial or source code for it please. I used following code ‘Namespaces Imports System.Data Imports System.Data.OleDb Imports System.Data.Common ‘other declearations in Public class form Public Class Form1 Inherits System.Windows.Forms.Form Dim dtBook As DataTable Dim daBook As New OleDb.OleDbDataAdapter Dim Srch As String Dim MaxRowsBook As Integer Private DataTable As DataTable Private CurrRec As Integer …

Member Avatar
Member Avatar
+0 forum 2

Friends I m workin on vb.net ado.net oledb, I have also added datagrid Control to my form for retriving database from .Mdb file i used following code [code] 'decleared Name Space Imports System.Data.OleDb 'Dicleared Variabls in Class Form1 Dim con As New OleDb.OleDbConnection Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String Dim inc As Integer Dim MaxRows As Integer 'created Navigate Records() 'class txtSno.Text = ds.Tables("SLAPhonebook").Rows(inc).Item("SNo") txtName.Text = ds.Tables("SLAPhonebook").Rows(inc).Item("Name") txtLastName.Text = ds.Tables("SLAPhonebook").Rows(inc).Item("LastName") txtOrganization.Text = ds.Tables("SLAPhonebook").Rows(inc).Item("Organization") ' and so on... ' on form load () event i put following coding con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=D:\SLAPhonebook.mdb" sql = …

Member Avatar
Member Avatar
+0 forum 5

Help With Add, Delete, Edit and Update Record (with Datatable Method) I Created a Software with OleDb .mdb database previously Using Dataset Method, but I was unable to Connect Datagrid with it on real Basis, I mean when I Clicked Next Record Button it only Moves in TextBoxes (Which were Connected with Dataset) but on DataGrid it was not moving the Curser to next record or previous Record, Now with the Help and Advice of <Adatapost> (A member of this Forum) I Resolved it with using DataTable function instead of dataset Now Plz I need a little more Help here, …

Member Avatar
+0 forum 0

I have a small project in c# and ms-access I use query builder to manage my tables in ms-access. the problem is, select qeury works great, update query works great, delete doesn't work , and there is no error msg!!!!!!1 please help!! [CODE] OleDbDataAdapter adapter = new OleDbDataAdapter(); string queryString = "SELECT [Id],[Name] FROM [myTable]"; cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _conStrName + ";User Id=admin;Password=;"; OleDbConnection connection = new OleDbConnection (cn.ConnectionString); adapter.SelectCommand = new OleDbCommand (queryString, connection); adapter.SelectCommand.CommandText = queryString; OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter); adapter.Update(ds.Tables["myTable"]); return ds;* [/CODE]

Member Avatar
Member Avatar
+0 forum 1

The End.