Save variable to session in VB.net - vb.net

This is the code inside of my Handler.ashx at the end of this loop I want to save the variable whereclause to the session so it will know what the previous where clause was.
I am open to any way of doing it, but I believe saving to the session would help me complete this.
I tried: Session["whereclause"] = whereclause but it gave me an error
'4.3 Filtering implementation
If Not (FilterTerm = "" Or FilterCol = "") Then
If Not (FilterCol = "[Study Time]") And InStr(whereclause, "WHERE", vbTextCompare) = 0 Then
whereclause = whereclause & " WHERE " & FilterCol & " = '" & FilterTerm & "'"
ElseIf InStr(whereclause, "WHERE", vbTextCompare) = 0 And FilterCol = "[Study Time]" Then
whereclause = whereclause & " WHERE " & FilterCol & " = '12/30/1899 " & FilterTerm & "'"
ElseIf (FilterCol = "[Study Time]") Then
whereclause = whereclause & " AND " & FilterCol & " = '12/30/1899 " & FilterTerm & "'"
Else
whereclause = whereclause & " AND " & FilterCol & " = '" & FilterTerm & "'"
End If
End If

Related

How concatenate recordset variables to use filter method - Vba

I would like to concatenate multiple variables on my recordset filter. Here more information :
rs is recordset
titre can be M. or Mme or S. (come from rs)
Nom is of the form (come from rs) : FirstName LastName (with space between)
but I can't. I tried :
space = " "
rs.Filter = "[titre+ space + Nom] = '" & oLookFullName & "' and nomEntreprise = '" & objContact.CompanyName & "'"
Concatenation = rs!titre + " " + rs!Nom
rs.Filter = "Concatenation = '" & oLookFullName & "'"
Any ideas ?
EDIT
#Gustav, I tried your code with split and it seems the filter contains the correct value but just after I have this if loop and in this case rs.EOF is true while the contact exists... why ?
If rs.EOF Then 'Or (rs.BOF = True) Then
Debug.Print oLookFullName & " is not found."
End If
Try with:
rs.Filter = "[titre] & ' ' & [Nom] = '" & oLookFullName & "' And [nomEntreprise] = '" & objContact.CompanyName & "'"
or:
rs.Filter = "[titre] = '" & Split(oLookFullName, " ")(0) & "' And [Nom] = '" & Split(oLookFullName, " ")(1) & "' And [nomEntreprise] = '" & objContact.CompanyName & "'"

Need Help for Updating database in vb.net

Someone knows why I got an exception when the code running at cmd.ExecuteNonQuery()? when I update Date, it runs perfectly but when I update the Finish date, I got that error.
This is the code
Call connection()
If txt_UpCom.Text = "" Or cbCom.SelectedItem = "" Then
If txt_ComNew.Enabled = True Then
MessageBox.Show("Please fill the entire data!")
End If
Else
Try
Dim str As String
If cbCom.SelectedItem = "Date" Or cbCom.SelectedItem = "Finish Date" Then
Dim comdate As String = dateCom.Value.ToString("yyyy-MM-dd")
str = "UPDATE complain SET " & cbCom.SelectedItem & "= '" & comdate & "' WHERE ComplainID = '" & txt_UpCom.Text & "'"
Else
str = "UPDATE complain SET " & cbCom.SelectedItem & " = '" & txt_ComNew.Text & "' WHERE ComplainID = '" & txt_UpCom.Text & "'"
End If
cmd = New MySql.Data.MySqlClient.MySqlCommand(str, conn)
cmd.ExecuteNonQuery()
msgBoxSuccess.ShowDialog()
conn.Close()
Catch ex As Exception
MessageBox.Show("Unable to Update")
End Try
End If
This is the table in database
As #Jacek Wróbel mentioned in the comments, you should keep the column names between [] (square brackets) or "" (double quots). The same thing goes for table names (or any other SQL objects for that matter).
Long story short, change this part of your code:
If cbCom.SelectedItem = "Date" Or cbCom.SelectedItem = "Finish Date" Then
Dim comdate As String = dateCom.Value.ToString("yyyy-MM-dd")
str = "UPDATE complain SET " & cbCom.SelectedItem & "= '" & comdate & "' WHERE ComplainID = '" & txt_UpCom.Text & "'"
Else
str = "UPDATE complain SET " & cbCom.SelectedItem & " = '" & txt_ComNew.Text & "' WHERE ComplainID = '" & txt_UpCom.Text & "'"
End If
to this:
If cbCom.SelectedItem = "Date" Or cbCom.SelectedItem = "Finish Date" Then
Dim comdate As String = dateCom.Value.ToString("yyyy-MM-dd")
str = "UPDATE `complain` SET `" & cbCom.SelectedItem & "` = '" & comdate & "' WHERE `ComplainID` = '" & txt_UpCom.Text & "'"
Else
str = "UPDATE `complain` SET `" & cbCom.SelectedItem & "` = '" & txt_ComNew.Text & "' WHERE `ComplainID` = '" & txt_UpCom.Text & "'"
End If
Note: I prefer to keep things consistant, so I added [] to each object whether it contains spaces or not.

ASP Classic on IIS 7 - variable data seems to pass between sessions

I have a page that collects data that is passed to it via http querystring and parses it and stores it in SQL. The data includes drive data about the server checking in. The check in occurs with a custom VB service.
What seems to happen intermittently, is drive data from one server seems to end up stored under another server. Here's a meta representation of the mix-up:
SERVER--TIME--CDRIVE--DDRIVE--NOTE
SERVER-A--1215--355--126--This is a normal check-in for Server-A
SERVER-B--1215--1267--426--This is a normal check-in for Server-B
SERVER-A--1230--1267--426--This is a garbled check-in with B's data instead of A's
SERVER-B--1230--1267--426--This is normal, but is where the bad data comes from
The mix-up does not occur between any particular servers, just between two servers that happened to check in at the same moment. I have tried disabling output caching and most recently I have tried adding "session.abandon" to my code.
Any guidance would be greatly appreciated. I don't do web development as my primary task. I didn't even notice the issue until I set the drive data to loop after 7 days instead of looping every 24 hours.
Here's the code - the include just creates an "oconn" sql object.
<%language=vbscript%>
<!--#include file="includes/db.inc"-->
<%
'Variable Declaration
'---------------------
Private hsid
'COMMON SECTION
'--------------
hsid = request.querystring("hsid")
if isnumeric(hsid) then
hsid = cint(hsid)
else
oconn.close
session.abandon
response.end
end if
sessionid = now() & hsid
Session("SessionID") = sessionid
response.write(Session("SessionID") & "<br/>")
htime = now()
hdate = datevalue(htime)
hhour = hour(htime)
hminute = minute(htime)
hdur = 300
hver = request.querystring("hver")
if hver = "" then
hver = "Legacy"
end if
hupver = request.querystring("hupver")
if hupver = "" then
hupver = "Legacy"
end if
response.write("hupver = *" & hupver & "*<br/>")
'Stop processing if the server is not supported or the Company is not Icon.
sql = "select u.txtUserFirstName from users u inner join site s on u.fkySiteID = s.keySiteID inner join Company c on s.fkyCompanyID = c.keyCompanyID where u.keyUserID = " & hsid & " and u.binUserSupport = 1 and c.binCompanyIcon = 1"
set rs = oconn.execute(sql)
if rs.eof then
response.write("No Support")
session.abandon
response.end
end if
rs.close
set rs = nothing
function getfree(inputstring)
gfindex = instr(inputstring,"-")
' response.write(gfindex & "<br/>")
outputstring = mid(inputstring, 1, gfindex-1)
getfree = outputstring
end function
function getfull(inputstring)
gfindex = instr(inputstring,"-")
outputstring = mid(inputstring, gfindex+1, len(inputstring)-gfindex)
getfull = outputstring
end function
'DRIVES SECTION
'--------------
drivelow = 0 'captures whether any drive is below 1 GB free space for later use
Private drivearr(3,26)
'drivearr(1,x) is for thresholds, (2,x) is for free space, (3,x) is for total capacity
'all drives will actually count from 3 (c) to 26 (z)
'we collect drive threshold settings from the DriveThreshold table, or otherwise generate a default entry for it.
sql = "select * from DriveThreshold where fkyUserID = " & hsid
set rs = oconn.execute(sql)
if not rs.eof then
drivearr(1,3) = cdbl(rs("intcdrive"))*1024
drivearr(1,4) = cdbl(rs("intddrive"))*1024
drivearr(1,5) = cdbl(rs("intedrive"))*1024
drivearr(1,6) = cdbl(rs("intfdrive"))*1024
drivearr(1,7) = cdbl(rs("intgdrive"))*1024
drivearr(1,8) = cdbl(rs("inthdrive"))*1024
drivearr(1,9) = cdbl(rs("intidrive"))*1024
drivearr(1,10) = cdbl(rs("intjdrive"))*1024
drivearr(1,11) = cdbl(rs("intkdrive"))*1024
drivearr(1,12) = cdbl(rs("intldrive"))*1024
drivearr(1,13) = cdbl(rs("intmdrive"))*1024
drivearr(1,14) = cdbl(rs("intndrive"))*1024
drivearr(1,15) = cdbl(rs("intodrive"))*1024
drivearr(1,16) = cdbl(rs("intpdrive"))*1024
drivearr(1,17) = cdbl(rs("intqdrive"))*1024
drivearr(1,18) = cdbl(rs("intrdrive"))*1024
drivearr(1,19) = cdbl(rs("intsdrive"))*1024
drivearr(1,20) = cdbl(rs("inttdrive"))*1024
drivearr(1,21) = cdbl(rs("intudrive"))*1024
drivearr(1,22) = cdbl(rs("intvdrive"))*1024
drivearr(1,23) = cdbl(rs("intwdrive"))*1024
drivearr(1,24) = cdbl(rs("intxdrive"))*1024
drivearr(1,25) = cdbl(rs("intydrive"))*1024
drivearr(1,26) = cdbl(rs("intzdrive"))*1024
else
sql = "insert into DriveThreshold (fkyUserID, intCDrive, intDDrive, intEDrive, intFDrive, intGDrive, intHDrive, intIDrive, intJDrive, intKDrive, intLDrive, intMDrive, intNDrive, intODrive, intPDrive, intQDrive, intRDrive, intSDrive, intTDrive, intUDrive, intVDrive, intWDrive, intXDrive, intYDrive, intZDrive) values (" & hsid & ", 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)"
oconn.execute(sql)
for i = 3 to 26
drivearr(1,i) = 1*1024
next
end if
rs.close
set rs = nothing
'Load the null value (-1) for all positions in the drivearr for free spacce (2,x) and total capacity (3,x)
for i = 3 to 26
drivearr(2,i) = -1
drivearr(3,i) = -1
next
cdrive = request.querystring("c") 'collect C Drive data
' response.write("cdrive=" & cdrive & "<br/>")
if len(cdrive) > 3 then
drivearr(2,3) = getfree(cdrive)
drivearr(3,3) = getfull(cdrive)
end if
if drivearr(2,3) > -1 then 'only if C Drive is being monitored do we do the rest of the work
ddrive = request.querystring("d")
' response.write("ddrive=" & ddrive & "<br/>")
if len(ddrive) > 3 then
drivearr(2,4) = getfree(ddrive)
drivearr(3,4) = getfull(ddrive)
end if
edrive = request.querystring("e")
' response.write("edrive=" & edrive & "<br/>")
if len(edrive) > 3 then
drivearr(2,5) = getfree(edrive)
drivearr(3,5) = getfull(edrive)
end if
fdrive = request.querystring("f")
if len(fdrive) > 3 then
drivearr(2,6) = getfree(fdrive)
drivearr(3,6) = getfull(fdrive)
end if
gdrive = request.querystring("g")
if len(gdrive) > 3 then
drivearr(2,7) = getfree(gdrive)
drivearr(3,7) = getfull(gdrive)
end if
hdrive = request.querystring("h")
if len(hdrive) > 3 then
drivearr(2,8) = getfree(hdrive)
drivearr(3,8) = getfull(hdrive)
end if
idrive = request.querystring("i")
if len(idrive) > 3 then
drivearr(2,9) = getfree(idrive)
drivearr(3,9) = getfull(idrive)
end if
jdrive = request.querystring("j")
if len(jdrive) > 3 then
drivearr(2,10) = getfree(jdrive)
drivearr(3,10) = getfull(jdrive)
end if
kdrive = request.querystring("k")
if len(kdrive) > 3 then
drivearr(2,11) = getfree(kdrive)
drivearr(3,11) = getfull(kdrive)
end if
ldrive = request.querystring("l")
if len(ldrive) > 3 then
drivearr(2,12) = getfree(ldrive)
drivearr(3,12) = getfull(ldrive)
end if
mdrive = request.querystring("m")
if len(mdrive) > 3 then
drivearr(2,13) = getfree(mdrive)
drivearr(3,13) = getfull(mdrive)
end if
ndrive = request.querystring("n")
if len(ndrive) > 3 then
drivearr(2,14) = getfree(ndrive)
drivearr(3,14) = getfull(ndrive)
end if
odrive = request.querystring("o")
if len(odrive) > 3 then
drivearr(2,15) = getfree(odrive)
drivearr(3,15) = getfull(odrive)
end if
pdrive = request.querystring("p")
if len(pdrive) > 3 then
drivearr(2,16) = getfree(pdrive)
drivearr(3,16) = getfull(pdrive)
end if
qdrive = request.querystring("q")
if len(qdrive) > 3 then
drivearr(2,17) = getfree(qdrive)
drivearr(3,17) = getfull(qdrive)
end if
rdrive = request.querystring("r")
if len(rdrive) > 3 then
drivearr(2,18) = getfree(rdrive)
drivearr(3,18) = getfull(rdrive)
end if
sdrive = request.querystring("s")
if len(sdrive) > 3 then
drivearr(2,19) = getfree(sdrive)
drivearr(3,19) = getfull(sdrive)
end if
tdrive = request.querystring("t")
if len(tdrive) > 3 then
drivearr(2,20) = getfree(tdrive)
drivearr(3,20) = getfull(tdrive)
end if
udrive = request.querystring("u")
if len(udrive) > 3 then
drivearr(2,21) = getfree(udrive)
drivearr(3,21) = getfull(udrive)
end if
vdrive = request.querystring("v")
if len(vdrive) > 3 then
drivearr(2,22) = getfree(vdrive)
drivearr(3,22) = getfull(vdrive)
end if
wdrive = request.querystring("w")
if len(wdrive) > 3 then
drivearr(2,23) = getfree(wdrive)
drivearr(3,23) = getfull(wdrive)
end if
xdrive = request.querystring("x")
if len(xdrive) > 3 then
drivearr(2,24) = getfree(xdrive)
drivearr(3,24) = getfull(xdrive)
end if
ydrive = request.querystring("y")
if len(ydrive) > 3 then
drivearr(2,25) = getfree(ydrive)
drivearr(3,25) = getfull(ydrive)
end if
zdrive = request.querystring("z")
if len(zdrive) > 3 then
drivearr(2,26) = getfree(zdrive)
drivearr(3,26) = getfull(zdrive)
end if
'Test to see if any of the drives are low
for i = 3 to 26
if drivearr(2,i) > -1 then
if cdbl(drivearr(2,i)) < cdbl(drivearr(1,i)) then drivelow = 1
end if
next
if drivelow = 1 then 'we set the toggle for the server having 1+ drives low in the Users table.
sql = "update Users set binServerDriveLow = 1 where keyUserID = " & hsid
oconn.execute(sql)
else
sql = "update Users set binServerDriveLow = 0 where keyUserID = " & hsid
oconn.execute(sql)
end if
'----This section determines which of 2016 5-minute-intervals the check-in time matches and rounds the check-in time
rdate = hdate
rdayofweek = weekday(hdate)
rhour = hhour
rsequence = round(hminute/5,0)
if rsequence = 12 then
rsequence = 0
rhour = rhour + 1
if rhour = 24 then
rhour = 0
rdate = dateadd("d", 1, rdate)
rdayofweek = weekday(rdate)
end if
end if
rminute = rsequence * 5
rindex = ((rdayofweek-1) * 288) + (rhour * 12) + rsequence + 1
rtime = rdate & " " & timeserial(rhour, rminute, 0)
response.write("rindex: " & rindex & "<br />")
'----Determines which key value matches the sequence number in the DailyDrive table for use in data punch-down.
sql = "select keyDriveDailyID from DriveDaily where intDriveDailyIndex = " & rindex & " and fkyUserID = " & hsid
set rs = oconn.execute(sql)
if not rs.eof then 'if the sequence is found in the table and has a key value then update the table, otherwise....
ddkey = rs("keyDriveDailyID")
sql = "update DriveDaily set datDriveDailyTime = '" & rtime & "', CDrive = " & drivearr(2,3) & ", CDriveCap = " & drivearr(3,3) & ", DDrive = " & drivearr(2,4) & ", DDriveCap = " & drivearr(3,4) & ", EDrive = " & drivearr(2,5) & ", EDriveCap = " & drivearr(3,5) & ", FDrive = " & drivearr(2,6) & ", FDriveCap = " & drivearr(3,6) & ", GDrive = " & drivearr(2,7) & ", GDriveCap = " & drivearr(3,7) & ", HDrive = " & drivearr(2,8) & ", HDriveCap = " & drivearr(3,8) & ", IDrive = " & drivearr(2,9) & ", IDriveCap = " & drivearr(3,9) & ", JDrive = " & drivearr(2,10) & ", JDriveCap = " & drivearr(3,10) & ", KDrive = " & drivearr(2,11) & ", KDriveCap = " & drivearr(3,11) & ", LDrive = " & drivearr(2,12) & ", LDriveCap = " & drivearr(3,12) & ", MDrive = " & drivearr(2,13) & ", MDriveCap = " & drivearr(3,13) & ", NDrive = " & drivearr(2,14) & ", NDriveCap = " & drivearr(3,14) & ", ODrive = " & drivearr(2,15) & ", ODriveCap = " & drivearr(3,15) & ", PDrive = " & drivearr(2,16) & ", PDriveCap = " & drivearr(3,16) & ", QDrive = " & drivearr(2,17) & ", QDriveCap = " & drivearr(3,17) & ", RDrive = " & drivearr(2,18) & ", RDriveCap = " & drivearr(3,18) & ", SDrive = " & drivearr(2,19) & ", SDriveCap = " & drivearr(3,19) & ", TDrive = " & drivearr(2,20) & ", TDriveCap = " & drivearr(3,20) & ", UDrive = " & drivearr(2,21) & ", UDriveCap = " & drivearr(3,21) & ", VDrive = " & drivearr(2,22) & ", VDriveCap = " & drivearr(3,22) & ", WDrive = " & drivearr(2,23) & ", WDriveCap = " & drivearr(3,23) & ", XDrive = " & drivearr(2,24) & ", XDriveCap = " & drivearr(3,24) & ", YDrive = " & drivearr(2,25) & ", YDriveCap = " & drivearr(3,25) & ", ZDrive = " & drivearr(2,26) & ", ZDriveCap = " & drivearr(3,26) & " where keyDriveDailyID = " & ddkey
' response.write(sql)
' response.write("<br />")
' response.end
oconn.execute(sql)
else '...otherwise add a new entry to the table.
sql = "select numCounter from Counter where txtTableName = 'DriveDaily'"
set cs = oconn.execute(sql)
if not cs.eof then
ddkey = cdbl(cs("numCounter"))
end if
cs.close
set cs = nothing
sql = "insert into DriveDaily(keyDriveDailyID, fkyUserID, datDriveDailyTime, intDriveDailyIndex, CDrive, CDriveCap, DDrive, DDriveCap, EDrive, EDriveCap, FDrive, FDriveCap, GDrive, GDriveCap, HDrive, HDriveCap, IDrive, IDriveCap, JDrive, JDriveCap, KDrive, KDriveCap, LDrive, LDriveCap, MDrive, MDriveCap, NDrive, NDriveCap, ODrive, ODriveCap, PDrive, PDriveCap, QDrive, QDriveCap, RDrive, RDriveCap, SDrive, SDriveCap, TDrive, TDriveCap, UDrive, UDriveCap, VDrive, VDriveCap, WDrive, WDriveCap, XDrive, XDriveCap, YDrive, YDriveCap, ZDrive, ZDriveCap) values (" & ddkey & ", " & hsid & ", '" & rtime & "', " & rindex & ", " & drivearr(2,3) & ", " & drivearr(3,3) & ", " & drivearr(2,4) & ", " & drivearr(3,4) & ", " & drivearr(2,5) & ", " & drivearr(3,5) & ", " & drivearr(2,6) & ", " & drivearr(3,6) & ", " & drivearr(2,7) & ", " & drivearr(3,7) & ", " & drivearr(2,8) & ", " & drivearr(3,8) & ", " & drivearr(2,9) & ", " & drivearr(3,9) & ", " & drivearr(2,10) & ", " & drivearr(3,10) & ", " & drivearr(2,11) & ", " & drivearr(3,11) & ", " & drivearr(2,12) & ", " & drivearr(3,12) & ", " & drivearr(2,13) & ", " & drivearr(3,13) & ", " & drivearr(2,14) & ", " & drivearr(3,14) & ", " & drivearr(2,15) & ", " & drivearr(3,15) & ", " & drivearr(2,16) & ", " & drivearr(3,16) & ", " & drivearr(2,17) & ", " & drivearr(3,17) & ", " & drivearr(2,18) & ", " & drivearr(3,18) & ", " & drivearr(2,19) & ", " & drivearr(3,19) & ", " & drivearr(2,20) & ", " & drivearr(3,20) & ", " & drivearr(2,21) & ", " & drivearr(3,21) & ", " & drivearr(2,22) & ", " & drivearr(3,22) & ", " & drivearr(2,23) & ", " & drivearr(3,23) & ", " & drivearr(2,24) & ", " & drivearr(3,24) & ", " & drivearr(2,25) & ", " & drivearr(3,25) & ", " & drivearr(2,26) & ", " & drivearr(3,26) & ")"
' response.write(sql)
' response.end
oconn.execute(sql)
sql = "update Counter set numCounter = " & ddkey+1 & " where txtTableName = 'DriveDaily'"
oconn.execute(sql)
end if
rs.close
set rs = nothing
end if
'HEARTBEAT SECTION-------------------------------------------------------------
' DATETIME SUBSECTION
' -------------------
dt = request.querystring("dt")
if dt = "" then
' do nothing
else
dtyear = mid(dt,1,4)
dtmonth = mid(dt,5,2)
dtday = mid(dt,7,2)
dthour = mid(dt,9,2)
dtminute = mid(dt,11,2)
dtstring = dtmonth & "/" & dtday & "/" & dtyear & " " & dthour & ":" & dtminute
end if
sql = "select datHeartLast, intHeartNext from Users where keyUserID = " & hsid
set rs = oconn.execute(sql)
if not rs.eof then
hlast = rs("datHeartLast")
hnext = rs("intHeartNext")
end if
rs.close
set rs = nothing
response.write("<br />hlast = " & hlast & "<br />hnext = " & hnext)
if hnext > 0 then
hgap = datediff("s",hlast,htime)
if hnext + 60 < hgap then
sql = "select numCounter from Counter where txtTableName = 'Heart'"
set rs = oconn.execute(sql)
if not rs.eof then
heartid = cdbl(rs("numCounter"))
end if
rs.close
set rs = nothing
sql = "insert into Heart (keyHeartID, fkyServerID, datHeartDownStart, datHeartDownEnd) values (" & heartid & ", " & hsid & ", '" & hlast & "', '" & htime & "')"
oconn.execute(sql)
sql = "update Counter set numCounter = " & heartid + 1 & " where txtTableName = 'Heart'"
oconn.execute(sql)
end if
else
sql = "update Users set datHeartFirst = '" & htime & "' where keyUserID = " & hsid
oconn.execute(sql)
end if
sql = "update Users set datHeartLast = '" & htime & "', intHeartNext = " & hdur & ", datHeartDT = '" & dtstring & "', fkyHeartTicketID = null, binHeartEmailSent = 0, txtHeartVersion = '" & hver & "', txtHeartUpVersion = '" & hupver & "' where keyUserID = " & hsid
oconn.execute(sql)
oconn.close
set oconn = nothing
response.write(rindex & " " & htime & " " & rtime)
session.abandon
%>

want to update record if exists and insert if not exists

want to update record if exists and insert if not exists into vsolv_trn_tsalesregdump Is tsalesregdump_name is unique in table vsolv_trn_tsalesregdump
when i click check box that particular row should be check on other table and how to use it for loop in form loop i can use the "tsalesdump_date,tsalesdump_name,executivename_executive" this three if the value is same its go to update and otherwise its not to same its move on insert how can i write it can any 1help me
if i have use two table one temp and other 1 is orginal\ temp table =vsolv_tmp_tsalesdump orginal table=vsolv_trn_tsalesregdump.
if already i hav save the data in orginal table,again if i hav assing data for temp table and view in radgrid if select and submit the button its go to check on orginal table if the value is already there its update it otherwise insert how can use it
Protected Sub btn_Submit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_Submit.Click
lblerrmsg.Text = ""
Dim chk As CheckBox
Dim lbtn As LinkButton
Dim Res As Long
Dim lobjrow As DataRow
Dim lObjErrTable As New DataTable
Dim a As Integer = 0
Dim dtcarbooking As New DataTable
Dim dtDumpBooking As New DataTable
Dim lsRefid As String = String.Empty
Dim dtdumpsample As New DataTable
Dim name As String = String.Empty
If Check_Validation() = True Then
Exit Sub
End If
Gobjdbconn.OpenConn()
lObjErrTable = Error_TabelFill()
For i As Integer = 0 To GVUpload.Items.Count - 1
chk = GVUpload.Items(i).FindControl("chkupload")
If chk.Checked = True Then
lsRefid = GVUpload.Items(i).GetDataKeyValue("tsalesdump_gid").ToString()
MsSql = ""
MsSql &= "Select tsalesdump_gid,tsalesdump_date,tsalesdump_name,executivename_executive,tsalesdump_vch_no,tsalesdump_debit,tsalesdump_credit"
MsSql &= " from vsolv_tmp_tsalesdump as a"
MsSql &= " left join vsolv_trn_executivename as b on a.tsalesdump_name = b.executivename_particulars"
MsSql &= " where tsalesdump_gid = '" & lsRefid & "' and tsalesdump_isremoved = 'N'"
dtDumpBooking = Gobjdbconn.GetDataTable(MsSql)
MsSql = ""
MsSql &= "Insert into vsolv_trn_tsalesregdump(tsalesregdump_date,tsalesregdump_name,tsalesregdump_executive,tsalesregdump_vch_no"
MsSql &= " ,tsalesregdump_debit,tsalesregdump_credit,tsalesregdump_importby)"
MsSql &= " Values ('" & Format(CDate(dtDumpBooking.Rows(0).Item("tsalesdump_date")), "yyyy-MMM-dd").ToString() & "'"
MsSql &= ",'" & dtDumpBooking.Rows(0).Item("tsalesdump_name").ToString() & "'"
MsSql &= ",'" & dtDumpBooking.Rows(0).Item("executivename_executive").ToString() & "'"
MsSql &= " ,'" & dtDumpBooking.Rows(0).Item("tsalesdump_vch_no").ToString() & "'"
MsSql &= " ,'" & dtDumpBooking.Rows(0).Item("tsalesdump_debit").ToString() & "','" & dtDumpBooking.Rows(0).Item("tsalesdump_credit").ToString() & "','SIVA')"
MnResult = Gobjdbconn.ExecuteNonQuerySQL(MsSql)
If MnResult = 1 Then
MsSql = ""
MsSql &= " Delete from vsolv_tmp_tsalesdump where tsalesdump_gid = '" & lsRefid & "'"
Gobjdbconn.ExecuteNonQuerySQL(MsSql)
Else
lobjrow = lObjErrTable.NewRow()
a = a + 1
lobjrow("Sno") = a
lobjrow("Booking Ref No") = dtcarbooking.Rows(0).Item("tsalesregdump_name").ToString
lobjrow("Description") = "Duplicate Record"
lObjErrTable.Rows.Add(lobjrow)
End If
End If
Next
POPSummary()
If Not lObjErrTable Is Nothing Then
If lObjErrTable.Rows.Count > 0 Then
Call Pop_Data(lObjErrTable)
End If
End If
End Sub
If you want to update record if already exists else insert in SQL then you can achieve by following: You need to change MsSql string for Insert command
MsSql = "" + _
"IF EXISTS(Select tsalesregdump_name From vsolv_trn_tsalesregdump Where tsalesregdump_name = '" & dtDumpBooking.Rows(0).Item("tsalesdump_name").ToString() & "') " + _
"BEGIN " + _
" Update vsolv_trn_tsalesregdump " + _
" Set tsalesregdump_date = '" & Format(CDate(dtDumpBooking.Rows(0).Item("tsalesdump_date")), "yyyy-MMM-dd").ToString() & "' " + _
" ,tsalesregdump_executive = '" & dtDumpBooking.Rows(0).Item("executivename_executive").ToString() & "' " + _
" ,tsalesregdump_vch_no = '" & dtDumpBooking.Rows(0).Item("tsalesdump_vch_no").ToString() & "' " + _
" ,tsalesregdump_debit = '" & dtDumpBooking.Rows(0).Item("tsalesdump_debit").ToString() & "' " + _
" ,tsalesregdump_credit = '" & dtDumpBooking.Rows(0).Item("tsalesdump_credit").ToString() & "' " + _
" ,tsalesregdump_importby = 'SIVA' " + _
" Where tsalesregdump_name = '" & dtDumpBooking.Rows(0).Item("tsalesdump_name").ToString() & "' " + _
"END " + _
"ELSE " + _
"BEGIN " + _
" Insert into vsolv_trn_tsalesregdump(tsalesregdump_date,tsalesregdump_name,tsalesregdump_executive,tsalesregdump_vch_no " + _
" ,tsalesregdump_debit,tsalesregdump_credit,tsalesregdump_importby) " + _
" Values ('" & Format(CDate(dtDumpBooking.Rows(0).Item("tsalesdump_date")), "yyyy-MMM-dd").ToString() & "' " + _
" ,'" & dtDumpBooking.Rows(0).Item("tsalesdump_name").ToString() & "' " + _
" ,'" & dtDumpBooking.Rows(0).Item("executivename_executive").ToString() & "' " + _
" ,'" & dtDumpBooking.Rows(0).Item("tsalesdump_vch_no").ToString() & "' " + _
" ,'" & dtDumpBooking.Rows(0).Item("tsalesdump_debit").ToString() & "','" & dtDumpBooking.Rows(0).Item("tsalesdump_credit").ToString() & "','SIVA') " + _
"END "
MnResult = Gobjdbconn.ExecuteNonQuerySQL(MsSql)
I am assuming here that tsalesregdump_name is unique.

Passing an Empty/Null Date variable in VBA to an SQL UPDATE statement

I have an excel userform with various textboxes, some are fields to enter dates. The user can then save their entries.
At this point, I connect to an access backend via an ADO connection. The values entered by a user are passes to an SQL string, e.g.
strSQL = "UPDATE tblDECONVERSION_DATA SET tblDECONVERSION_DATA.Status = '" & NewBusiness_WorkQueue.Decon_CaseStatus & "', " & _
"tblDECONVERSION_DATA.DMS = '" & NewBusiness_WorkQueue.Decon_DMS & "', " & _
"tblDECONVERSION_DATA.DateRecieved = #" & Format(NewBusiness_WorkQueue.Decon_DateRecieved, "mm/dd/yyyy") & "#, " & _
"tblDECONVERSION_DATA.WireDate = #" & Format(NewBusiness_WorkQueue.Decon_WireDate, "mm/dd/yyyy") & "#, " & _
"tblDECONVERSION_DATA.LastEditXID = '" & CurrUser & "', tblDECONVERSION_DATA.LastEditDate = #" & Now & "# " & _
"WHERE (((tblDECONVERSION_DATA.CaseID)=" & ID & "));"
adoRecSet.Open Source:=strSQL, ActiveConnection:=dbconnect, CursorType:=adOpenDynamic, LockType:=adLockOptimistic
However, some of the date fields can be left blank, meaning for example the NewBusiness_WorkQueue.Decon_DateRecieved variable being empty. This causes a syntax error. How can I pass a Null or Empty date variable in the SQL statement that both VBA and the access database will accept?
strSQL = "UPDATE tblDECONVERSION_DATA SET tblDECONVERSION_DATA.Status = '" & _
NewBusiness_WorkQueue.Decon_CaseStatus & "', " & _
"tblDECONVERSION_DATA.DMS = '" & NewBusiness_WorkQueue.Decon_DMS & "', " & _
"tblDECONVERSION_DATA.DateRecieved = " & _
DateOrNull(NewBusiness_WorkQueue.Decon_DateRecieved) & ", " & _
"tblDECONVERSION_DATA.WireDate = " & _
DateOrNull(NewBusiness_WorkQueue.Decon_WireDate) & ", " & _
"tblDECONVERSION_DATA.LastEditXID = '" & CurrUser & _
"', tblDECONVERSION_DATA.LastEditDate = #" & Now & "# " & _
"WHERE tblDECONVERSION_DATA.CaseID=" & ID & ";"
An example function:
Function DateOrNull(v) As String
Dim rv as String
If IsDate(v) Then
rv = " #" & Format(v, "mm/dd/yyyy") & "# "
Else
rv = " null "
End If
DateOrNull = rv
End Function