Click here to Skip to main content
15,887,175 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Message Box just before creating print preview Pin
Vasudevan Deepak Kumar29-May-08 23:53
Vasudevan Deepak Kumar29-May-08 23:53 
QuestionCompiling Questions Pin
Maffyx29-May-08 14:17
Maffyx29-May-08 14:17 
AnswerRe: Compiling Questions Pin
jzonthemtn29-May-08 15:21
jzonthemtn29-May-08 15:21 
GeneralRe: Compiling Questions Pin
Maffyx29-May-08 15:25
Maffyx29-May-08 15:25 
QuestionReturning an array from a function Pin
Eric Burns29-May-08 11:47
Eric Burns29-May-08 11:47 
AnswerRe: Returning an array from a function Pin
Luc Pattyn29-May-08 12:09
sitebuilderLuc Pattyn29-May-08 12:09 
GeneralRe: Returning an array from a function Pin
Tony Richards29-May-08 14:04
Tony Richards29-May-08 14:04 
QuestiondataSets and TableAdapters Pin
ghazanfarKhan29-May-08 8:18
ghazanfarKhan29-May-08 8:18 
Hi all.

I have written a simple application in vb.net (2.0) that reads data from an excel sheet (previously stored in focus databases) and stores it into a sql server database. I am using typed datasets and table adapters to store the data. I have an "Import" button whose event handler does the following in turn.

1. connect to the excel sheet through an ole db conn
2. read the contents in a while loop using the executeReader() method
3. store the values in variables where necessary conversions and validations are performed.
4. call an insert method in the associated dataset tableAdapter that stores these processed values in the sql db.

This is all working as it should. Now I need to check for existing records before I import the values - Ignore completely if the value is found.
According to msdn, I should be able to use my tableAdapters update method by passing a dataSet/Table/Row(s). So this is how I tried to tackle it.


Legend:
lbf = my DataSet
lbf_COKEnCOLE = the Database table associated with lbf DataSet

GetRecordByIdDateLab = runs the following SQL Query on the data
SELECT *
FROM lbf_COKEnCOLE
WHERE (ORIGINATOR_ID = @ORIGINATOR_ID) AND (SMPL_DTE = @SMPL_DTE) AND (LAB_NUM = @LAB_NUM)
(The actual sql refers to all the columns by names instead of using *)

Dim tableadapter As New lbfTableAdapters.lbf_COKEnCOLETableAdapter
Dim dataTable As lbf.lbf_COKEnCOLEDataTable = Nothing
            'check for existing record by using GetRecordByIdDateLab method
            dataTable = tableadapter.GetRecordByIdDateLab(ORIGINATOR_ID, SMPL_DTE, LAB_NUM)
            If Not dataTable Is Nothing Then
                If dataTable.Rows.Count > 0 Then
                    If Not dataTable(0).ORIGINATOR_ID = Nothing Then
                        'Row = dataTable(0)
                        dataTable(0).TURN = TURN
                        dataTable(0).SMPL_ANALYS_HOUR = SMPL_ANALYS_HOUR
                        dataTable(0).SMPL_ANALYS_MIN = SMPL_ANALYS_MIN
                        dataTable(0).MOISTURE = MOISTURE
                        dataTable(0).S = S
                        dataTable(0).VM = VM
                        dataTable(0).ASH = ASH
                        dataTable(0).HARDNESS = HARDNESS
                        dataTable(0).STABILITY = STABILITY
                        dataTable(0).QRT_TUMBLE = TUMBLE_30M
                        dataTable(0).APTSPC_GRAV = APTSPC_GRAV
                        dataTable(0).FREE_SWL_I = FREE_SWL_I
                        dataTable(0).PULV8TH = PULV8TH
                        dataTable(0).QRT_PULV = QRT_PULV
                        dataTable(0).SCR_4 = SCR_4
                        dataTable(0).SCR_3 = SCR_3
                        dataTable(0).SCR_2 = SCR_2
                        dataTable(0).SCR_1NHALF = SCR_1NHALF
                        dataTable(0).SCR_1 = SCR_1
                        dataTable(0).SCR_3QRT = SCR_3QRT
                        dataTable(0).SCR_HALF = SCR_HALF
                        dataTable(0).SCR_38THS = SCR_38THS
                        dataTable(0).SCR_QRT = SCR_QRT
                        dataTable(0).QRT_PULV = QRT_PULV
                        dataTable(0).SCR_8TH = SCR_8TH
                        dataTable(0).SCR_20M = SCR_20M
                        dataTable(0).SCR_30M = SCR_30M
                        dataTable(0).SCR_50M = SCR_50M
                        dataTable(0).SCR_100M = SCR_100M
                        dataTable(0).SCR_PAN = SCR_PAN
                        dataTable(0).SCR_QRT_PLUS = SCR_QRT_PLUS
                        dataTable(0).SAMPL_LOC = SAMPL_LOC


                        tableadapter.Update(dataTable)  '<<THIS IS WHERE IT CRASHES WITH "A first chance exception of type 								'System.InvalidOperationException' occurred in System.Data.dll

                    End If



			'The following tableAdapter works perfectly whenever the condition is true (for new entries that is)
                ElseIf dataTable.Rows.Count = 0 Then
                    tableadapter.InsertQuery(counter, ORIGINATOR_ID, SMPL_DTE, LAB_NUM, TURN, SMPL_ANALYS_HOUR, SMPL_ANALYS_MIN, _
                                    MOIS_GRAV, MOISTURE, S, VM, ASH, HARDNESS, STABILITY, QRT_TUMBLE, TUMBLE_30M, APTSPC_GRAV, _
                                    FREE_SWL_I, PULV8TH, QRT_PULV, SCR_4, SCR_3, SCR_2, SCR_1NHALF, SCR_1, SCR_3QRT, SCR_HALF, _
                                    SCR_38THS, SCR_QRT, SCR_8TH, SCR_20M, SCR_30M, SCR_50M, SCR_100M, SCR_PAN, SCR_QRT_PLUS, SAMPL_LOC)

                End If
            End If


****************************************
More details:

I have DataTable under "Watch" and the value for it shows up as "dataTable has not been declared". This ofcourse is misleading because it is, plus intellisense picks it up where I'm updating the column values by referencing them with dataTable(0).columnName

I have been wondering if
dataTable = tableadapter.GetRecordByIdDateLab(ORIGINATOR_ID, SMPL_DTE, LAB_NUM)

does what its supposed to do, ie. return a dataTable with the matching record. I tried to recieve the data in a row but it only allowed it to be saved in a datatable instantiated in this manner. Furthermore, when I read the values read into the datatable, each column value shows up only as lbf_COKEnCOLE.column (something to this effect) in curly braces. Almost everything else thats returned, like index values and what not that I suppose is used to keep the schema of the table has errors in it.

Any suggestions and help would be greatly appreciated!! I am trying to avoid suddenly using command objects when I'm doing everything else through a data Access layer. lastly, I have read and reread this msdn page
http://msdn.microsoft.com/en-us/library/ms233819(VS.80).aspx

and am trying to do everything as shown here, obviously to no avail Frown | :(


All .net people out there, if you would help this awkward programmer, it would be greatly appreciated! Thanks

~Ghazanfar
GeneralRe: dataSets and TableAdapters Pin
Tony Richards29-May-08 14:07
Tony Richards29-May-08 14:07 
QuestionDisable keyboard events Pin
Member 224184329-May-08 5:32
Member 224184329-May-08 5:32 
AnswerRe: Disable keyboard events Pin
jzonthemtn29-May-08 5:47
jzonthemtn29-May-08 5:47 
AnswerRe: Disable keyboard events Pin
parth.p29-May-08 7:24
parth.p29-May-08 7:24 
QuestionCannot Hide Message Box in Print Preview Pin
BooleanTrue29-May-08 4:37
professionalBooleanTrue29-May-08 4:37 
Answer[Duplicate Post. Ignore] Re: Cannot Hide Message Box in Print Preview Pin
Vasudevan Deepak Kumar29-May-08 23:54
Vasudevan Deepak Kumar29-May-08 23:54 
QuestionCheck if GDI+ bitmap has transparency Pin
TrekkieDK29-May-08 4:05
TrekkieDK29-May-08 4:05 
AnswerRe: Check if GDI+ bitmap has transparency Pin
Guffa29-May-08 7:02
Guffa29-May-08 7:02 
GeneralRe: Check if GDI+ bitmap has transparency Pin
Christian Graus29-May-08 13:31
protectorChristian Graus29-May-08 13:31 
GeneralRe: Check if GDI+ bitmap has transparency Pin
Guffa29-May-08 15:18
Guffa29-May-08 15:18 
AnswerRe: Check if GDI+ bitmap has transparency Pin
Luc Pattyn29-May-08 21:52
sitebuilderLuc Pattyn29-May-08 21:52 
QuestionSaving PDF on local hard disk which is read by browser control Pin
Sunil Shindekar28-May-08 23:13
Sunil Shindekar28-May-08 23:13 
AnswerRe: Saving PDF on local hard disk which is read by browser control Pin
jzonthemtn29-May-08 1:40
jzonthemtn29-May-08 1:40 
GeneralRe: Saving PDF on local hard disk which is read by browser control Pin
Sunil Shindekar29-May-08 3:21
Sunil Shindekar29-May-08 3:21 
QuestionNeed help with a project, I am really stumped! Pin
Ogre72228-May-08 20:04
Ogre72228-May-08 20:04 
AnswerRe: Need help with a project, I am really stumped! Pin
Eduard Keilholz28-May-08 20:42
Eduard Keilholz28-May-08 20:42 
GeneralRe: Need help with a project, I am really stumped! Pin
Ogre72229-May-08 2:44
Ogre72229-May-08 2:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.