ADO.NET Custom Data Access Code?

Apr 20, 2010

I'm currently working on my VB.NET certification and I'm using Murach's Visual Basic 2008 for my class textbook. Chapter 16 of the text covers writing my own ADO.NET data access codes. The code I have included here is for two classes of the project:

frmAddModifyCustomerDB.vb is prewritten by murach for this assignment and CustomerDB.vb is included written in the book as my assignment to build but not prewritten for me in the solution. According to the assignment, frmAddModifyCustomerDB.vb should not be modified unless instructed by the book. The procedure in question is Private Sub btnAccept_Click on the line that reads: "If Not CustomerDB.UpdateCustomer(customer, newCustomer) Then".After copying the CustomerDB.vb class directly from the book the assignment stated that the database should update properly when using the UpdateCustomer function that is fired when the Accept button is clicked. Every time I tried to modify a customer when doing this I kept getting the Database Error message box and the changes would be canceled.

After playing with the code I changed the "If Not CustomerDB.UpdateCustomer(customer, newCustomer) Then" to check against the boolean return from CustomerDB.vb by inserting "= False". When the modified code reads "If Not CustomerDB.UpdateCustomer(customer,
newCustomer) = False Then" the application updates properly and does not fire any exceptions. I'm confused by this because the book specified that I should not need to modify the code for the Add/Modify form in order for this to work.

Public Class frmAddModifyCustomer
Public addCustomer As Boolean
Public customer As Customer

[code].....

View 3 Replies


ADVERTISEMENT

Disposing Of Custom Data Access Layer References?

Oct 1, 2010

Our application uses a custom DataAccessLayer class almost exclusively, and within that we do use Data Access Application Block (currently version 2). We are getting the infamous "GetOrdinal" error sporadically. We are not using out-of-method connections. We are using DAAB version 2. Below is a typical example of our DAL methods:

Public Function MyDALMethod(ByVal Param1 As Integer, ByVal Param2 As Integer) As System.Data.IDataReader
Dim db As Database = DatabaseFactory.CreateDatabase()

[Code].....

My main question is should these DAL references be disposed somehow? It's a custom class written in VB.NET, so it doesn't implement IDisposable so I'm not sure if there's anything to be done or not, but we do have errors and issues (like the GetOrdinal problem) which seem to be load-related, and I'm wondering if this is part of the problem.

View 1 Replies

Code To Export Data From Excel To Access?

Jun 2, 2011

I Have code for display excel data in datagriedview can anyone suggest me how i can export this data to ms-access tables.

Try
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet

[code]......

View 1 Replies

Application Code Affecting Access Database Data?

Sep 21, 2010

I have an application half built which accesses a Access (2003)Database File. From within the application I am able to change the data in the Access File using a Data Grid. The changes to the Data File are saved and can be recalled, changed or otherwisemanipulated however, when I add too or change any of the applicationcode the Access file reverts back to it's original state losing any data or changes that has been made.

View 3 Replies

Code Review: ADO.NET Data Access Utility Class (VB)?

Mar 6, 2009

When I started at my current employer I inherited a project from a previous developer and in that project was a data access utility class that tries to simplify a lot of the code involved in making calls and retrieving data back from the database. Over time it has been modified to add more overloaded forms of functions, and now I am looking at possible suggestions from the StackOverflow community.What do you think should be added? Removed?odified?Note:It would be nice if this class could remain compatible to VB.NET in the .NET 2.0 framework. We are also developing in 3.5, but I would like to have something that is generally going to work across most frameworks (so no LINQ, etc.) Also, please refrain from unnecessary answers that consist of nothing but "Use nHibernate" or other tools.

My class:
Public Class DataAccess
Public Shared Function ReturnScalar(ByVal CmdStr As String) As String

[code].....

View 2 Replies

DB Access Code - Copy Just The Structure Of The Tables And Not The Data?

Mar 13, 2009

Here is the:

Imports System.Data.OleDb
'Add reference to Access then
Imports Microsoft.Office.Interop
Imports Microsoft.VisualBasic

[CODE]...

I am using this to copy tables in an Access database(2003). the questions I have are:

1. How can I make this more 'obejct oriented'?

2. How can I copy just the structure of the tables and not the data?

(Currently both are occuring)

View 3 Replies

.net - C# Code For Reading Multiple Attachments From Microsoft Access Attachment Data Type Using DataReader?

Aug 1, 2011

I have multiple documents stored in Attachment data type in Access database. UsingDataReader, I need to read multiple attachments along with their file name and store them on the file system

View 1 Replies

Have A List Box With A Custom Data Template Populate With User Data?

Jul 2, 2011

I am working on a project and I want to have a list box with a custom data template populate with user data. My question is, when I click on an item in the list box, how can I tell what item I selected? Basically, if I select "kevin", I want to display his data. If I select Dave, I want to display his data. I do not know how to get the data our after it is bound...

View 4 Replies

.net - Provide Access To This Custom DAL?

May 13, 2010

I'm writing a custom DAL (VB.NET) for an ordering system project. I'd like to explain how it is coded now, and receive some alternate ideas to make coding against the DAL easier/more readable. The DAL is part of an n-tier (not n-layer) application, where each tier is in it's own assembly/DLL.

The DAL consists of several classes that have specific behavior. For instance, there is an Order class that is responsible for retrieving and saving orders. Most of the classes have only two methods, a "Get" and a "Save," with multiple overloads for each. These classes are marked as Friend and are only visible to the DAL (which is in it's own assembly).

In most cases, the DAL returns what I will call a "Data Object." This object is a class that contains only data and validation, and is located in a common assembly that both the BLL and DAL can read.To provide public access to the DAL, I currently have a static (module) class that has many shared members. A simplified version looks something like this:

Public Class DAL
Private Sub New
End Sub
Public Shared Function GetOrder(OrderID as String) as OrderData

[code].....

This cleans it up a bit, but it leaves a lot of classes that only have references to other classes, which I don't like for some reason.Without resorting to passing DB specific instructions (like where clauses) from BLL to DAL, what is the best or most common practice for providing a single point of access for the DAL?

View 2 Replies

Can't Access Custom Property?

May 15, 2010

I created a new DataGridViewColumn type called DataGridViewGradeColumn.

Public Class DataGridViewGradeColumn
Inherits DataGridViewTextBoxColumn
Public Property AssignmentName As String

[code].....

View 1 Replies

Asp.net - Can Linq2sql Do This Without A Lot Of Custom Code?

Jan 13, 2009

how to make linq2sql behave like my custom code used to, I want to check to make sure that it isn't already "built" in behavior that I can just use by setting up the relationships right in the designer...

Very simple example: I have two tables: Person and Notes, with a 1 to many relationship (1 Person, many notes), linked by Person.ID->Note.PersonID.

I have a stored procedure (all data access is done via SP's and I plan on continuing that) which makes the Link2SQL a bit more work for me.

sp_PersonGet(@ID int) which returns the person record and sp_PersonNotesGet(@PersonID) which returns a set of related notes for this person.So far so good, I have an object:

Dim myPerson As Person = db.PersonGet(pnID).Single

and I can access my fields: myPerson.Name, myPerson.Phone etc.and I can also do a

Dim myNotes As Notes = db.PersonNotesGet(pnID)

to get a set of notes and I can iterate thru this list like:

For Each N As Note In myNotes
( do something)
Next[code].....

Basically, Linq2SQl would need to call 2 stored procedures each time a Person record is created...Is this doable "out of the box", or is this something I need to code around for myself?

View 3 Replies

Example Code To Work To Access An Access Database Through Automation?

Oct 13, 2010

I have a similar problem posted in the forum similar to this : started learning VB. I am not able to get my example code to work to access an Access database through automation. The author of my book suggested that I might not have the correct Jet 4.0 engine. The specs I have are: MSJet40.dll, Dated 7/14/2009, Prod Ver 4.00.9756.0.

View 3 Replies

Access A Checkbox In Custom Dialog Box

Jul 27, 2011

I'm trying to create a installation setup for my VB.net application. I need to insert a custom action while setup is running. So I add a Checkbox Dialog box to my setup. And I add a dll to the setup installation to capture Before Install and After Install events. Those are works fine. But I cannot access my check box value in those events. [code]

View 2 Replies

.net - Code Smith 6 Using Custom Utility?

Mar 30, 2012

I have a CodeSmith 6 project setup in Visual Studio. I added a class with a shared method (VB), but cannot refer to it in my template. I also tried adding an assembly reference to the project DLL, but that didn't work either. How can I use my own utilities like this?

View 1 Replies

Adding Custom Code To A Report

Feb 6, 2011

I want to custom code to a report. For example, I have a text box, txtABC on the report. I want to assign it a value from variable, when report runs. How to do it.

View 1 Replies

Custom Code Designer Generated?

Jan 20, 2011

but it's something I'm pretty consistently needing for the sake of my own sanity, so:If you add a Settings file to any project in Visual Studio, VS provides a GUI making it quick/easy to add a new Setting entry and assign it a Type; at that point the actual code-behind is automagically created with a variable and a property exposing that variable.Can we build our own designers to generate code this way, with a GUI allowing for those quick/easy variable/property assignments?

View 4 Replies

Custom Code For Rdlc Report?

Jun 14, 2010

In my report I want to display the dollar amoumt in textboxs.So I set the textbox property Format as currency.My question is that I want to reports show brackets for negative dollar values. It works out except "$" sign being showing whenever there''s an amount showing. I want to remove this "$" sign from the report.

View 1 Replies

Use A Custom Format String On .e.g A Zip Code?

Feb 11, 2010

What is the right way to use a custom format string on .e.g a zip code?

The zip code in the database might have 9 characters, but the program should only output five. Using string.format("{0:#####}","322318825") will output "322318825", the entire 9-digit code.

Zip codes are only an example. This is actually for a dynamic format function that takes two arguments, one is the format and the other is a database field value. Therefore, it cannot work by being strongly typed.

View 5 Replies

VS 2008 Creating 'custom Code'

Aug 6, 2010

I have a form that is populated with specific data for each user. The user chooses this data themselves.I plan on saving this data in the application settings or via xml serialization.What I want to do, is allow users to generate a unique code for that data so that they can supply this code to others and all they will have to do is copy and paste it into their client and that data will populate for them.I could just allow users to trade XML files, but I want it to be easier than that.The form is basically setup this way;

Picture - Data 1, Data 2, Data 3, Data 4
Picture - Data 1, Data 2, Data 3, Data 4

The pictures correlate to pictures that are numbered anywhere from 0-600. The data can be any integer value from 0 - 200.

View 16 Replies

Access Form Controls From Within Custom Control?

Dec 6, 2011

I have a form named VBProject It has two TextBoxes and one custom control named MyControl which is created in another project.MyControl's project has a form inside, named Form3. When My control is loaded it needs to find all controls in my VBProject and add them into a listbox which is in Form3. Then Show the Form3. In the end ListView need to shows name and text of textboxes but it shows nothing. Here are my codes:

MyControl's Load_Event:

Dim i As Integer = 0
MessageBox.Show("Control Count:" + Me.Controls.Count.ToString)
For Each MyObject In Me.Controls
If TypeOf MyObject Is TextBox Then

[code]...

View 1 Replies

Access GMAIL For Storage In Custom CRM Using SQL Server DB?

Mar 12, 2010

I have a client who wants his custom-written CRM to be able to access his sales people's emails so that, effectively, a history of email conversations between customer and salesperson is stored inside the CRM's database.

The CRM is written in VB 2008 and the database is SQL Server 2008. The only email these people use, in the shop and on the road, is GMAIL. Each sales person has their own GMAIL address. Thats how they operate.

If they're on the road and respond to a customer's email inquiry about a product, they would like that email conversation to be stored in a table in the database. I think thats the part I cant wrap my head around. How to get access to the email data (knowing the user id and password) and doing so from VB 2008

Update: A free or close to free solution would be preferred.

View 2 Replies

Access Of A Shared Member [...] In Custom Class?

Jun 9, 2012

I have a custom class called "Time" with the following function, for determining if one Time equals another Time.

Public Shared Shadows Function Equals(ByVal Time1 As Time, ByVal Time2 As Time) As Boolean
Dim x(2) As Integer
x(0) = CInt(Time1.Hour)
x(1) = CInt(Time1.Minute)

[code].....

Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.I know it shouldn't do any harm, just let the compiler skip evaluation, but is it a way of getting rid of this warning?

View 6 Replies

CommandBuilder Custom SQL - Access The Items Through The DR Object?

Sep 25, 2009

I have reached a situation where it probably makes more sense to pass custom Update and Insert commands to a CommandBuilder. I see that this can be done, but I have not found an example of how. The problem that I run into is this: The CommandBuilder iterates through the rows calling the Update or Insert command as needed. Writing the SQL for those would require accessing the items in the row. How does the CommandBuilder insert the row fields into the SQL? If I were doing it myself, I would be doing something like:

For Each DR as Datarow in Datatable

which would allow me to access the items through the DR object. What does the CommandBuilder expose for custom SQL to access the items in the row?

View 8 Replies

Reading Custom Properties From An Access File?

Oct 6, 2009

I'm trying to build an app that will read custom properties set in an accdb file. Basically, I'm trying to build a Front End updater (Yes I know there are others already built, but they don't work the way I want). The Custom properties are initially set manually by pressing the Office button, going to Manage, then Database Properties and selecting the Custom tab.

I've got most of the code set up, but my sticking point is how to read the custom properties.

Following is the function I use within Access VBA to get the properties, but obviously this is not going to work in VB.Net.

[Code].....

I think I need to replace one or more of the 4 lines after the On Error (yes I know I need to change the Error trapping too). I'm guessing I need to connect to the database file (an accdb, btw) and then go from there to define the container and documents collections.

View 1 Replies

Winforms - Use Custom Roles For User Access?

Sep 2, 2009

I have a winforms (VB 2008) based app that I'm developing and I want to use custom roles for user access.Application Layout:I have a Main form that opens a login form when certain actions occur.The Login form intern uses an authentication class that I've created, to authenticate users and set access rights.On my Applications settings page, I have Authentication Mode set to Application-defined because I cannot use Windows Authentication in the environment where this will be deployed.

The application uses a MS SQL 2005 db and the 3 tables I'm using in the authentication process are the User_Account , User_Roles and User_Access tables. The combination of an account in the User_Account and the roles within the User_Roles table are the bases for the User_Access table. Using the User_Access table is how I assign access to the various functions within the application

Authentication Method:To authenticate a user, I'm using the "My.User.CurrentPrincipal" (Code below) method. The My.User object works great and allows the use of "My.User.Name" property throughout the app when referring to the currently authenticated user.

Access Method:In order to set the current users access levels I'm using a function within my Authentication class and passing in My.User.Name as a variable. The function uses a Dataset Table Adaptor and a Select Case statement inside a For loop to assign all the access levels for the user (Function code below).

My Problem:This method of assigning access rights to a user does work but it's not persistent throughout the application as the My.User object is.I would like to find a way to create custom roles through the My.User object using its .IsInRole property. I would like to have these roles dynamically created using my User_Roles table.This would allow the custom roles to be used throughout my application using the My.User.IsInRole ("MyRole")syntax ...similar to how I'm currently able to use My.User.Name.Unfortunately the only roles I can currently validate against are the built in Windows
type accounts (Adminisrator ...ect.).

'User Authentication example:
If Authenticate.CheckPassword(tbxUserName.Text, strPassword) Then
My.User.CurrentPrincipal = New GenericPrincipal(New GenericIdentity(tbxUserName.Text), Nothing)[code].....

View 1 Replies

.net - My SUM Function - Rdlc - Custom Code -total?

Nov 6, 2011

I would like to pass a value and add to it with the previous value thats what I want.The below code doesn't work...I can't understand the problem..Actually its for rdlc - total purpose I need it.My Code

public MyValue as Decimal=0
public Function AddToSum(ByVal quantity as Decimal) as Decimal
MyValue=AddToSum+quantity
AddToSum=MyValue
return AddToSum

[Code]...

View 1 Replies

Create Some Custom Button Items In Code?

Mar 18, 2011

I create some custom button items in code.I need to have some code for their Button_Click event and set Button.Checked = Not Button.Checked So I use this code:

[vb]
AddHandler MyAccount1Button.Click, AddressOf SubAccountButtonItem
AddHandler MyAccount2Button.Click, AddressOf SubAccountButtonItem
...

[code].....

View 5 Replies

Custom Code Into The Standard DotNetNuke Login?

Jun 18, 2009

Where can I find the function that handles the login for DNN? I would like to add custom features to the login and I don't see the function in Login. ascx.vb (unless I missed it).There is a tag and a tag that forms the login. I figure one of these has the actual "Login" button, but I cannot seem to figure out where they're coming from.[code]

View 2 Replies

How To Create A Custom Copy And Paste Code

Aug 6, 2010

I wasn't sure how to phrase this, so sorry if the title is misleading.I need some suggestions on how to create a custom copy and paste code. I have a form that is populated with specific data for each user. The user chooses this data themselves.

I plan on saving this data in the application settings or via xml serialization. What I want to do, is allow users to generate a unique code for that data so that they can supply this code to others and all they will have to do is copy and paste it into their client and that data will populate for them.I could just allow users to trade XML files, but I want it to be easier than that.[code...]

View 2 Replies

Set Custom Papersize To Printer From Code In .net 2005?

Mar 11, 2010

we have a vb.net windows appliacation that uses sql server as backend. we have created all reports for this application using crystal report that is embedded in visual studio 2005. everything is working fine except the reports specially which needs to be displayed is custome mode. we have used some code to dynamically set the printer settings because at runtime the original printer settings are unknown and we don't want to let user set printer settings manually everytime before taking the printout. so the question is, how to set a custom papersize programactically. here is the code snippet that we have used to set some printer settings in runtime :-

rpt.PrintOptions.PrinterName = Configuration.ConfigurationManager.AppSettings("DefaultPrinter")
rpt.PrintOptions.PaperOrientation = PaperOrientation.Landscape
rpt.PrintOptions.PaperSize = PaperSize.PaperFanfoldUS

we have usedreportdocument object to set printer options. we have two rpts which need to displayed in custom paper format. the formats are like 9X6 and 14X12. we have created these formats in server properties. now how to to set this from code? like in place of rpt.PrintOptions.PaperSize = PaperSize.PaperFanfoldUS...some sort of syntax which will let us to put the papersize in place ofPaperSize.PaperFanfoldUS...

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved