Click here to Skip to main content
15,923,120 members
Home / Discussions / Database
   

Database

 
AnswerRe: SQL-Instead of null value I have to display the text like NO Pin
Giorgi Dalakishvili30-May-08 1:16
mentorGiorgi Dalakishvili30-May-08 1:16 
GeneralRe: SQL-Instead of null value I have to display the text like NO Pin
Hesham Amin1-Jun-08 12:27
Hesham Amin1-Jun-08 12:27 
AnswerRe: SQL-Instead of null value I have to display the text like NO Pin
Hesham Amin1-Jun-08 12:24
Hesham Amin1-Jun-08 12:24 
QuestionWeird nullable DateTime issue... Pin
Harvey Saayman29-May-08 21:43
Harvey Saayman29-May-08 21:43 
AnswerRe: Weird nullable DateTime issue... Pin
The Nightcoder30-May-08 1:00
The Nightcoder30-May-08 1:00 
QuestionGetting size of database programatically using C# or VB.NET Pin
Zerox MXI29-May-08 21:35
Zerox MXI29-May-08 21:35 
AnswerRe: Getting size of database programatically using C# or VB.NET Pin
Hesham Amin30-May-08 5:23
Hesham Amin30-May-08 5:23 
Questionun-cooperative DataSets & TableAdapters Pin
ghazanfarKhan29-May-08 8:23
ghazanfarKhan29-May-08 8:23 
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
QuestionLotus Notes to SQL Replication Pin
madhuGM29-May-08 5:09
madhuGM29-May-08 5:09 
QuestionUsing select or set with exec Pin
ChrisFarrugia29-May-08 4:23
ChrisFarrugia29-May-08 4:23 
AnswerRe: Using select or set with exec Pin
Alsvha29-May-08 6:08
Alsvha29-May-08 6:08 
AnswerRe: Using select or set with exec Pin
SomeGuyThatIsMe29-May-08 7:59
SomeGuyThatIsMe29-May-08 7:59 
QuestionPrevent queries from SQL Injection attack in SQL Server 2005 Pin
salon29-May-08 2:22
salon29-May-08 2:22 
AnswerRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
SomeGuyThatIsMe29-May-08 2:28
SomeGuyThatIsMe29-May-08 2:28 
GeneralRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
salon29-May-08 3:32
salon29-May-08 3:32 
GeneralRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
SomeGuyThatIsMe29-May-08 4:02
SomeGuyThatIsMe29-May-08 4:02 
GeneralRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
Alsvha29-May-08 6:11
Alsvha29-May-08 6:11 
GeneralRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
SomeGuyThatIsMe29-May-08 7:52
SomeGuyThatIsMe29-May-08 7:52 
GeneralRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
Alsvha29-May-08 8:29
Alsvha29-May-08 8:29 
AnswerRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
Alsvha29-May-08 6:15
Alsvha29-May-08 6:15 
GeneralRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
salon29-May-08 22:41
salon29-May-08 22:41 
AnswerRe: Prevent queries from SQL Injection attack in SQL Server 2005 Pin
The Nightcoder30-May-08 1:17
The Nightcoder30-May-08 1:17 
QuestionTRIGGER problem!!!!!! Help me! [modified] Pin
Karan_TN29-May-08 2:16
Karan_TN29-May-08 2:16 
AnswerRe: TRIGGER problem!!!!!! Help me! Pin
The Nightcoder30-May-08 1:31
The Nightcoder30-May-08 1:31 
GeneralRe: TRIGGER problem!!!!!! Help me! Pin
Karan_TN30-May-08 21:16
Karan_TN30-May-08 21:16 

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.