Click here to Skip to main content
16,005,682 members
Home / Discussions / C#
   

C#

 
AnswerRe: Learning C# by example? Complete projects? Pin
Priya Prk18-Nov-08 9:47
Priya Prk18-Nov-08 9:47 
Questionscreensaver Pin
jugal_piet@indiatimes.com18-Nov-08 2:13
jugal_piet@indiatimes.com18-Nov-08 2:13 
AnswerRe: screensaver Pin
SeMartens18-Nov-08 2:18
SeMartens18-Nov-08 2:18 
JokeRe: screensaver Pin
Giorgi Dalakishvili18-Nov-08 2:28
mentorGiorgi Dalakishvili18-Nov-08 2:28 
AnswerRe: screensaver Pin
sph3rex18-Nov-08 2:28
sph3rex18-Nov-08 2:28 
AnswerRe: screensaver Pin
#realJSOP18-Nov-08 3:47
professional#realJSOP18-Nov-08 3:47 
AnswerRe: screensaver Pin
DaveyM6918-Nov-08 3:53
professionalDaveyM6918-Nov-08 3:53 
QuestionSpecified cast is not valid when getting data from database Pin
Matjaz-xyz18-Nov-08 1:46
Matjaz-xyz18-Nov-08 1:46 
Hi.

I want to get some data from my database... but i get this error. It worked on my other form... but i get an error on this one. What could be wrong?



-------------------------
<br />
                string DelalUR="" ;<br />
                double ZasluzekUre=0;<br />
                string izmena="";<br />
                double ZasluzekVsota=0;<br />
                string Skener="";<br />
                string podstavka="";<br />
<br />
// added some comments in english for CP.<br />
<br />
                <br />
                if (izbrano) // This checks if the data on the form has been entered<br />
                {<br />
<br />
                    DateTime start = new DateTime(prihodDat.Value.Year, prihodDat.Value.Month, prihodDat.Value.Day, (int)prihodH.Value, (int)prihodM.Value, 0);<br />
                    DateTime entry = new DateTime(odhodDat.Value.Year, odhodDat.Value.Month, odhodDat.Value.Day, (int)odhodH.Value, (int)odhodM.Value, 0);<br />
<br />
                    //ce je obratno - start minus entry pol pride minus na koncu ampak isti rezultat<br />
                    TimeSpan cas = entry - start;<br />
<br />
                    DelalUR = cas.Hours.ToString() + ":" + cas.Minutes.ToString();<br />
                    ZasluzekUre = cas.TotalMinutes / 60;<br />
<br />
// here the app. gets the string to use with manipulating the table - the correct name or something...<br />
                    if (rDopoldanska.Checked)<br />
                        izmena = "Dopoldanska";<br />
                    if (rPopoldanska.Checked)<br />
                        izmena = "Popoldanska";<br />
                    if (rNocna.Checked)<br />
                        izmena = "Nocna";<br />
<br />
                    if (radioButton1.Checked)<br />
                        Skener = "OCR";<br />
                    if (radioButton2.Checked)<br />
                        Skener = "Skener";<br />
<br />
<br />
<br />
                    // --------- BRANJE IZ BAZE - PRIDOBITEV PODSTAVKE -------------<br />
// Getting the data<br />
// Podstavka is a column from a table called SKENIRANJE (these three tables are the same, only podstavka has different values<br />
// Any table has ID, Izmena (this one has - "Dopoldanska", "Popoldanska, "Nocna") and Podstavka collumns.<br />
// all the collums are just plain text... except ID, ofcourse.<br />
                    string sqlCommSkeniranje = "SELECT Podstavka FROM Skeniranje WHERE Izmena = '" + izmena + "'";<br />
                    string sqlCommSkladisce = "SELECT Podstavka FROM Skladisce WHERE Izmena = '" + izmena + "'";<br />
                    string sqlCommZlaganje = "SELECT Podstavka FROM ZlaganjeDokumentov WHERE Izmena = '" + izmena + "'";<br />
                    string sqlComm="";<br />
                    OleDbConnection dbConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "C:\\baza.mdb");<br />
 <br />
// sets the correct SQL sentence corresponding the selected text on combobox<br />
                    if (comboDelovno.Text == "Skeniranje")<br />
                        sqlComm = sqlCommSkeniranje;<br />
                    if (comboDelovno.Text == "Skladišče")<br />
                        sqlComm = sqlCommSkladisce;<br />
                    if (comboDelovno.Text == "Zlaganje Dokumentov")<br />
                        sqlComm = sqlCommZlaganje;<br />
<br />
                    OleDbCommand dbComm = new OleDbCommand(sqlComm, dbConn);<br />
<br />
                    dbConn.Open();<br />
                    OleDbDataReader beri = dbComm.ExecuteReader();<br />
                    beri.Read(); // <<----- !!! ERROR APPEARS HERE !!! --------------------------------------<br />
                    podstavka = Convert.ToString(beri.GetString(0));  // sets the string with the value, gotten from the DB. Example: Skeniranje - Popoldanska or Skladisce - Nocna and so on...<br />
                    dbConn.Close();<br />

----------------------------------


The error report from JIT debugger

************** Exception Text **************
System.InvalidCastException: Specified cast is not valid.
   at System.Data.OleDb.ColumnBinding.ValueString()
   at System.Data.OleDb.OleDbDataReader.GetString(Int32 ordinal)
   at Osnova_za_studentske_ure.frmUporabnik.button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\milos\My Documents\Visual Studio 2008\Projects\Osnova za studentske ure\Osnova za studentske ure\frmUporabnik.cs:line 153
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Osnova za studentske ure
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Documents%20and%20Settings/milos/My%20Documents/Visual%20Studio%202008/Projects/Osnova%20za%20studentske%20ure/Osnova%20za%20studentske%20ure/bin/Debug/Osnova%20za%20studentske%20ure.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Accessibility
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Accessibility/2.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Data
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Transactions
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
System.Data.DataSetExtensions
    Assembly Version: 3.5.0.0
    Win32 Version: 3.5.21022.8 built by: RTM
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Data.DataSetExtensions/3.5.0.0__b77a5c561934e089/System.Data.DataSetExtensions.dll
----------------------------------------
System.Core
    Assembly Version: 3.5.0.0
    Win32 Version: 3.5.21022.8 built by: RTM
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Core/3.5.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------


Sorry for my bad english... but i hope you understand what i'm trying to say.

Thanks for your answers in advance!

Regards,
Matjaž

Força Barça!

AnswerRe: Specified cast is not valid when getting data from database Pin
Giorgi Dalakishvili18-Nov-08 2:11
mentorGiorgi Dalakishvili18-Nov-08 2:11 
GeneralRe: Specified cast is not valid when getting data from database Pin
Matjaz-xyz18-Nov-08 2:21
Matjaz-xyz18-Nov-08 2:21 
GeneralRe: Specified cast is not valid when getting data from database Pin
Giorgi Dalakishvili18-Nov-08 2:26
mentorGiorgi Dalakishvili18-Nov-08 2:26 
QuestionMultiple Choice Exam in C# Pin
TimmyC198318-Nov-08 0:17
TimmyC198318-Nov-08 0:17 
AnswerRe: Multiple Choice Exam in C# Pin
#realJSOP18-Nov-08 0:29
professional#realJSOP18-Nov-08 0:29 
GeneralRe: Multiple Choice Exam in C# Pin
sph3rex18-Nov-08 1:24
sph3rex18-Nov-08 1:24 
AnswerRe: Multiple Choice Exam in C# Pin
Pedram Behroozi18-Nov-08 0:36
Pedram Behroozi18-Nov-08 0:36 
QuestionGeneric Dictionary with weak reference value Pin
Seetha.R18-Nov-08 0:05
Seetha.R18-Nov-08 0:05 
AnswerRe: Generic Dictionary with weak reference value Pin
Guffa18-Nov-08 0:13
Guffa18-Nov-08 0:13 
GeneralRe: Generic Dictionary with weak reference value Pin
Simon P Stevens18-Nov-08 0:16
Simon P Stevens18-Nov-08 0:16 
GeneralRe: Generic Dictionary with weak reference value Pin
Seetha.R18-Nov-08 0:43
Seetha.R18-Nov-08 0:43 
GeneralRe: Generic Dictionary with weak reference value Pin
Seetha.R18-Nov-08 0:40
Seetha.R18-Nov-08 0:40 
AnswerRe: Generic Dictionary with weak reference value Pin
Simon P Stevens18-Nov-08 0:14
Simon P Stevens18-Nov-08 0:14 
QuestionNaming Conventions Pin
AmbitiousBeginner17-Nov-08 23:29
AmbitiousBeginner17-Nov-08 23:29 
AnswerRe: Naming Conventions Pin
dan!sh 17-Nov-08 23:39
professional dan!sh 17-Nov-08 23:39 
AnswerRe: Naming Conventions Pin
Manas Bhardwaj17-Nov-08 23:39
professionalManas Bhardwaj17-Nov-08 23:39 
AnswerRe: Naming Conventions Pin
Simon P Stevens17-Nov-08 23:50
Simon P Stevens17-Nov-08 23:50 

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.