如何将日期值转换为变量?

时间:2014-02-24 13:34:24

标签: mysql vb.net visual-studio-2008

如何将值带入日期变量,我收到错误

  

无法将mysql datetime值转换为system.datetime

我正在使用visual studio 2008。 如何理清这个问题?      Dim connStr As String                 Dim SQLstr As String

            connStr = String.Format("server=" + LoginForm1.GlobalVariables.serveripaddress + "; user id=" + LoginForm1.GlobalVariables.dbusername + "; password=" + LoginForm1.GlobalVariables.dbpassword + "; database=" + LoginForm1.GlobalVariables.dbnamebroadcast + "; pooling=false; Convert Zero Datetime=True;Allow Zero Datetime=true")
            Dim conn = New MySqlConnection(connStr)
            conn.Open()

            Dim reader As MySqlDataReader
            Dim bct21, bct24, bct27, bct30 As Date

            Dim bct0, bct1, bct2, bct3, bct4, bct5, bct6, bct7, bct8, bct9, bct10, bct11, bct12, bct13, bct14, bct15, bct16, bct17, bct18, bct19, bct20, bct22, bct23, bct25, bct26, bct28, bct29, bct31, bct32, bct33, bct34, bct35 As String
            Dim bct90, bct36, bct37, bct38, bct39, bct40, bct41, bct42, bct43, bct44, bct45, bct46, bct47, bct48, bct50, bct51, bct52, bct53, bct54, bct55, bct56, bct57, bct58, bct59, bct60, bct61, bct62, bct63, bct64, bct65, bct66, bct67, bct68, bct69, bct70, bct71, bct72, bct73, bct74, bct75, bct76, bct77, bct78, bct80, bct81, bct82, bct83, bct84, bct85, bct86, bct87, bct88 As String

Dim clipdetails_ctn As New MySqlCommand("SELECT anatv.id ,anatv.channel_master_id,anatv.program_master_id,anatv.programTelecast,anatv.programDate,anatv.programStartTime,anatv.programEndTime,anatv.programLength,anatv.programSlot,anatv.isGEC,anatv.headline,anatv.reach,anatv.trp,anatv.sharedOrExclusive,anatv.clipType,anatv.typeComment,anatv.clipTag,anatv.tagCommentOther,anatv.tagCommentSpecialFeature,anatv.qcAutoUserId,anatv.qcAutoCurrentTime,anatv.qcAutoCurrentDate,anatv.qcReleaserId,anatv.qcReleaserCurrentTime,anatv.qcReleaserCurrentDate,anatv.user_master_id,anatv.currentTime,anatv.currentDate,anatv.c2n,anatv.c2nTime,anatv.c2nDate,anatv.clip_core_id,anatv.clip_start_time,anatv.clip_end_time,anatv.hourly_clip_name,anatv.cropped_clip_name,anatv.advertise_flag,anatv.breaking_news_flag,anatv.sector_id,anatv.keyword_list,anatv.is_headline,anatv.is_logo,by1.id,by1.clipId,by1.sector_master_id,by1.company_master_id,by1.byline_master_id,by1.otherDetails,by1.currentTime,by1.currentDate,by1.journ_profile_master_id,bykey.id,bykey.clipId,bykey.sector_master_id,bykey.company_master_id,bykey.keyword_master_id_2,bykey.programStatus,bykey.personality_master_id,bykey.beneficialStartTime,bykey.beneficialEndTime,bykey.beneficialTimeDifference,bykey.neutralStartTime,bykey.neutralEndTime,bykey.neutralTimeDifference,bykey.adverseStartTime,bykey.adverseEndTime,bykey.adverseTimeDifference,bykey.totalTimeInSeconds,bykey.keywordSummary,bykey.isKeyMessage,bykey.key_message_master_id,bykey.keyMessageSummary,bykey.source_master_id,bykey.sourceTonality,bykey.sourceSummary,bykey.keywordLevelTag,bykey.keywordLevelTagGEC,bykey.combination_master_id,bykey.clipSummary,bykey.currentDate,vis.id,vis.clipId,vis.sector_master_id,vis.company_master_id,vis.missOrHit,vis.reasonHitMiss,vis.MMB,vis.currentTime,vis.currentDate  from tb_kna_analysis_tv AS anatv,tb_kna_analysis_tv_byline AS by1,tb_kna_analysis_tv_byline_keyword  AS bykey,tb_kna_analysis_tv_visibility  AS vis,tb_kna_b_trans_broadcast_tag AS tag WHERE  anatv.clip_core_id= tag.id and anatv.id= by1.clipId and anatv.id= bykey.clipId and anatv.id=vis.clipId and tag.id = " + LoginForm1.GlobalVariables.qcindex.ToString, conn)
            reader = clipdetails_ctn.ExecuteReader()

            If reader.Read() Then

bct21 = reader.GetString(21) ' here I want take value from select query to bct21 

1 个答案:

答案 0 :(得分:0)

摆脱" .getstring"因为你不想看到字符串

bct21 = ctype(reader(21),datetime)

bct21 =reader(21)

您也可以使用

dim bct as new list (of Datetime)

然后

bct.add(reader(<whatevever>))

这将使您的变量更易于管理