Dim In_Total As Integer = 0
Dim Ph_Total As Integer = 0
Dim Day_In_Total As Integer = 0
Dim Day_Ph_Total As Integer = 0
Dim Course_Names1(1) As String
Qry = "SELECT DISTINCT Course_Name,Course_ID FROM Courses WHERE (Course_ID IN (SELECT Course_Id FROM Student_Courses_Pref WHERE student_Id IN (SELECT student_Id FROM Student_Info WHERE Inserted_date >= '" + Now.Month.ToString() + "-1-" + Now.Year.ToString() + "' and Inserted_date <= '" + Now.Date + "' and Branch_Code = '" + BName + "') and Branch_Code = '" + BName + "')) and Branch_Code = '" + BName + "' and Active = 'Y' order by Course_Id"
str = str + "<br> <br> <center><font face ='Verdana' size='+1'><B><U> Summary Report of " + MonthName(Now.Month()).ToString() + "," + Now.Year.ToString() + "</B></U> <br><br>"
com.CommandText = Qry
com.Connection = con
dr = com.ExecuteReader
str = str + "<table align='center' style='FONT-FAMILY: Verdana' bgcolor='#336699' width='100%'>"
str = str + "<tr style='FONT-WEIGHT: bold; FONT-SIZE: x-small;FONT-FAMILY: Verdana' bgColor='#b9ceee'><td align='center' width='3%'> Date </td>"
i = 0
While dr.Read
str = str + "<td align='Center' colspan='2' width='30%'>" + dr(0).ToString() + "</td>"
ReDim Preserve Course_Names1(i)
Course_Names1(i) = dr(1)
i = i + 1
End While
dr.Close()
str = str + "<td colspan ='2'>Total</td></tr>"
For i = 0 To Now.Day
If i = 1 Then
str = str + "<tr style='FONT-SIZE: x-small;FONT-FAMILY: Verdana' bgColor='#b9ceee'><td>" + i.ToString() + "<sup>st</sup>" + MonthName(Now.Month()).Substring(0, 3) + "</td>"
ElseIf i = 2 Then
str = str + "<tr style='FONT-SIZE: x-small;FONT-FAMILY: Verdana' bgColor='#b9ceee'><td>" + i.ToString() + "<sup>nd</sup>" + MonthName(Now.Month()).Substring(0, 3) + "</td>"
ElseIf i = 3 Then
str = str + "<tr style='FONT-SIZE: x-small;FONT-FAMILY: Verdana' bgColor='#b9ceee'><td>" + i.ToString() + "<sup>rd</sup>" + MonthName(Now.Month()).Substring(0, 3) + "</td>"
Else
str = str + "<tr style='FONT-SIZE: x-small;FONT-FAMILY: Verdana' bgColor='#b9ceee'><td>" + i.ToString() + "<sup>th</sup>" + MonthName(Now.Month()).Substring(0, 3) + "</td>"
End If
Qry = ""
For j = 0 To Course_Names1.Length - 1 'Here i got the error
Qry = "select count(student_id),enquiry_by from student_info where inserted_date = '" + MonthName(Now.Month).ToString() + " " + i.ToString() + "," + Now.Year.ToString() + "' and student_id in (select student_id from student_courses_pref where branch_code = '" + BName + "' and Course_id = '" + Course_Names1(j).ToString() + "') and branch_code ='" + BName + "' group by Enquiry_By "
com.CommandText = Qry
dr = com.ExecuteReader
While dr.Read()
If dr.HasRows Then
If UCase(dr(1).ToString()) = "I" Then
'str = str + "<td width='15%' bgcolor='#ffffff'>" + dr(0).ToString() + "</td><td width='15%' bgcolor='#c2ffc8'></td>"
In_Total += dr(0)
ElseIf UCase(dr(1).ToString()) = "P" Then
'str = str + "<td width='15%'bgcolor='#ffffff'></td><td width='15%' bgcolor='#c2ffc8'>" + dr(0).ToString() + "</td>"
Ph_Total += dr(0)
End If
Else
'str = str + "<td width='15%' bgcolor='#ffffff'></td><td width='15%' bgcolor='#c2ffc8'></td>"
End If
End While
If In_Total <> 0 Then
str = str + "<td width='15%' bgcolor='#ffffff'>" + In_Total.ToString() + "</td>"
Else
str = str + "<td width='15%' bgcolor='#ffffff'> </td>"
End If
If Ph_Total <> 0 Then
str = str + "<td width='15%' bgcolor='#c2ffc8'>" + Ph_Total.ToString() + "</td>"
Else
str = str + "<td width='15%' bgcolor='#c2ffc8'> </td>"
End If
dr.Close()
Day_In_Total += In_Total
Day_Ph_Total += Ph_Total
In_Total = 0
Ph_Total = 0
Next
str = str + "<td>" + Day_In_Total.ToString() + "</td><td>" + Day_Ph_Total.ToString() + "</td></tr>"
Day_In_Total = 0
Day_Ph_Total = 0
Next
str = str + "</tr></table>"
Where ist str defined?
Is it initialized with Dim str as string=""???
str = str + "<br> <br>...
Related
Im trying to send json object in Outlook using vba. Here is my code:
Dim Msg As Outlook.MeetingItem
Set Msg = Item
Set recips = Msg.Recipients
Dim regEx As New RegExp
regEx.Pattern = "^\w+\s\w+,\sI351$"
Dim URL As String
URL = "https://webhook.site/55759d1a-7892-4c20-8d15-3b8b7f1bf3b3"
For Each recip In recips
If regEx.Test(recip.AddressEntry) And recip.AddressEntry <> "Application Management Linux1, I351" Then
Dim convertedJson As Object
Set convertedJson = JsonConverter.ParseJson("{""fields"": 123}")
Set xhr = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xhr.Open "POST", URL, False
xhr.setRequestHeader "Content-Type", "application/json"
xhr.Send (convertedJson)
End If
Next
If I send just plane text it works well but i can't send convertedJson. Is it possible to send an object?
UPDATE
I can't even do Debug.Print convertedJson
I was tormented by these libraries in the end I did a very terrible thing
Dim flds, prt, id, smry, descrp, issu, name, lfbrkt, rtbrkt, cma, dbdots, jsTest, issuName As String
flds = "'fields'"
prt = "'project'"
id = "'id'"
smry = "'summary'"
descrp = "'description'"
issu = "'issuetype'"
issuName = "'Improvement'"
name = "'name'"
lfbrkt = "{"
rtbrkt = "}"
cma = ","
dbdots = ":"
jsTest = lfbrkt + flds + dbdots + " " + lfbrkt + vbCrLf + vbTab + prt + dbdots + " " + lfbrkt + vbCrLf + vbTab + vbTab + id + dbdots + " " + "30611" + vbCrLf + vbTab + rtbrkt + cma + vbCrLf + vbTab + smry + dbdots + " " + "'" + CStr(Msg.Subject) + "'" + cma + vbCrLf + vbTab + descrp + dbdots + " " + "'" + CStr(Msg.Body) + "'" + cma + vbCrLf + vbTab + issu + dbdots + " " + lfbrkt + vbCrLf + vbTab + vbTab + name + dbdots + " " + issuName + vbCrLf + vbTab + rtbrkt + vbCrLf + rtbrkt + rtbrkt
And I got this
please help me. this is a uni project and I keep getting the error "Conversion from string "" to type 'Double' is not valid." even when I made sure that everything is in the correct type, everything with a value...etc.
I want to insert some new rows in my access database, here is a picture of the table that Im trying to insert into
enter image description here
and this is the code
the error appears at the select statement in the sub w()
Dim c As Integer
Dim b As Double
Dim a, d, z As String
a = "'" + TextBox1.Text + "'"
b = CInt(TextBox2.Text)
c = CInt(TextBox3.Text)
d = "'" + TextBox4.Text + "'"
z = "'" + ComboBox1.SelectedItem + "'"
If ComboBox1.SelectedItem = "الجبيل" Then
w("insert into employees (em_id,em_name,m_id,city,phone,salary,password)" & " values (" + 32111 + "," + a + "," + 12303 + "," + z + "," + c + "," + b + "," + d + ")")
ElseIf ComboBox1.SelectedItem = "جدة" Then
w("insert into employees (em_id,em_name,m_id,city,phone,salary,password)" & " values (" + 32111 + "," + a + "," + 12302 + "," + z + "," + c + "," + b + "," + d + ")")
ElseIf ComboBox1.SelectedItem = "الرياض" Then
w("insert into employees (em_id, em_name,m_id,city,phone,salary,password)" & " values (" + 32111 + "," + a + "," + 12301 + "," + z + "," + c + "," + b + "," + d + ")")
End If
MsgBox("تم إضافة السجل بنجاح")
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
the sub w("") is:
Public Sub w(ByVal s As String)
Dim cum As New OleDbCommand(s, con)
cum.ExecuteNonQuery()
End Sub
problem is that it works on different forms (to diffident tables and stuff), but not in here...
what should I do?
code is building the email but it is only displaying one row when there is six. I got it correct on the text file but I need it to do the same in the email message. I think I got the for next statement in the wrong location. Here is the example of the code that I am having problem with. I do not know how to place the for next statement without interrupting the vbLine
For Each p In query
If p.Contract_No IsNot Nothing Then
ContractNo = p.Contract_No
Else
ContractNo = " "
End If
If p.Vendor_Name IsNot Nothing Then
VenderName = p.Vendor_Name
Else
VenderName = " "
End If
If p.Termination_Date IsNot Nothing Then
TerminationDate = p.Termination_Date
' ReportDateStr = ReportDate.ToString
TerminationDateStr = String.Format("{0:MM/dd/yyyy}", TerminationDate)
Else
TerminationDateStr = " "
End If
If p.Dept_Name IsNot Nothing Then
DeptName = p.Dept_Name
Else
DeptName = " "
End If
If p.Renewal_Option_Desc IsNot Nothing Then
RenewalOption = p.Renewal_Option_Desc
Else
RenewalOption = " "
End If
If p.Contract_Desc IsNot Nothing Then
ContractDesc = p.Contract_Desc
Else
ContractDesc = " "
End If
If p.Contact_Email IsNot Nothing Then
ContactEmail = p.Contact_Email
Else
ContactEmail = "** N/A ** "
End If
' sends email with attachment
EmailMsgBody = "-- TOTAL # OF CONTRACTS WITH FAILSAFE DATE ON " + DateStr + " IS: " + icnt.ToString + vbCrLf +
vbNewLine + " __________________ " +
vbNewLine +
vbNewLine + " *****Contracts**** " +
vbNewLine + " __________________ " +
vbNewLine +
vbNewLine + "Contract#" + " " + "Vender Name" + " " + "Termination Date" + " " + "Dept Name" + " " + "Renewal Option" + " " + "Contract Desc" + " " + "Email Address" +
vbNewLine + "------------" + " " + "-----------------" + " " + "---------------------" + " " + "--------------" + " " + "--------------------" + " " + "-----------------" + " " + "-----------------" +
vbNewLine + ContractNo.PadRight(18) + " " + _
VenderName.PadRight(38) + " " + _
TerminationDateStr.PadRight(26) + " " + _
DeptName.PadRight(27) + " " + _
RenewalOption.PadRight(45) + " " + _
ContractDesc.PadRight(32) + " " + _
ContactEmail.PadRight(11) + " "
please help me...
I load my database in the datagrid view and edit some cells.
Now I just need to update my database
here are my codes
Dim dT As DataTable = MyDB.ExecCommand("SELECT `Field Name` FROM `tblfield`", "wellsfargo").Tables(0)
Dim sSQL As String = ""
Dim dZ As DataTable = MyDB.ExecCommand("SELECT " & sColumn & " FROM `" + cboJob.Text.Trim + "`", "wellsfargo", 0).Tables(0)
dColumn = New DataTable
dColumn = MyDB.ExecCommand("SHOW COLUMNS IN tblrecord", "wellsfargo", 0).Tables(0)
If dZ.Rows.Count <> 0 Then
sSQL = "UPDATE " & sColumn & " FROM `" + cboJob.Text.Trim + "`"
MyDB.ExecQuery(sSQL, "wellsfargo")
Else
Dim sColumn As String = ""
For z As Integer = 0 To dT.Rows.Count - 1
If z = 0 Then
sColumn = "`" & dT.Rows(z).Item(0).ToString & "`"
Else
sColumn = sColumn & ",`" & dT.Rows(z).Item(0).ToString & "`"
End If
Next
sSQL = "INSERT INTO `" + MyJob + "` (" + sColumn + ") "
MyDB.ExecQuery(sSQL, "wellsfargo")
End If
Done.
I used this codes..
Try
Cursor = Cursors.WaitCursor
Dim sSQL As String
sSQL = "UPDATE `" + cboJob.Text.Trim + "` SET `Description` ='" + TextBox1.Text + "' WHERE `Description`= '" + Label2.Text + "' AND `Line Number` ='" + comList.Text + "'"
MyDB.ExecQuery(sSQL, "wellsfargo")
MsgBox("Updated!")
btnUpdate.Enabled = False
Catch ex As Exception
MsgBox("Select table first to Update")
End Try
Cursor = Cursors.Default
I am getting an error message as 'Incorrect Syntax near the keyword UNION.
The target site is -
Void ProcessResults(System.Data.OleDb.OleDbHResult)
and the stacktrace is as follows:-
at System.Data.OleDb.OleDbDataReader.ProcessResults(OleDbHResult hr) at System.Data.OleDb.OleDbDataReader.NextResult() at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) at MFActivityPlanning.NewStuffS.PopulateNewStuffsDataGrid()
The query is as follows:
strSelectQuery = "SELECT LED_ID AS PK_ID, FIRST_NAME + ' ' + LAST_NAME AS NAME"
+ " FROM M_LEADERLED INNER JOIN M_USER_DETAILS"
+ " ON M_LEADERLED.LED_ID = M_USER_DETAILS.PK_ID"
+ " WHERE (M_LEADERLED.LEADER_ID = " + Session["UserID"].ToString() + ""
+ " AND M_USER_DETAILS.ACTIVE = 1 AND M_LEADERLED.START_DATE <= Getdate()"
+ " AND M_LEADERLED.END_DATE > Getdate())"
+ " UNION SELECT PK_ID, FIRST_NAME + ' ' + LAST_NAME AS NAME"
+ " FROM M_USER_DETAILS WHERE PK_ID = " + Session["UserID"].ToString() + ";";
// Query for Idea
string selectIdea = "SELECT MWL.PK_ID AS PK_ID, 'Idea'+ ': ' + MI.TITLE AS TITLE,"
+ " 'Idea.aspx?id=' + CONVERT(VARCHAR, MI.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN M_IDEAS MI ON MWL.FK_OBJECT_ID = MI.PK_ID"
+ " INNER JOIN M_USER_DETAILS MUD ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = " + Convert.ToInt32(WatchType.Idea) + ""
+ " AND MWL.FK_USER_ID = " + userId + " AND MWL.IS_ACTIVE = 1";
// Query for Articles
string selectArticle = "SELECT MWL.PK_ID AS PK_ID, 'Articles' + ': ' + MA.TITLE AS TITLE,"
+ " 'Articles.aspx?id=' + CONVERT(VARCHAR, MA.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN M_ARTICLES MA ON MWL.FK_OBJECT_ID = MA.PK_ID"
+ " INNER JOIN M_USER_DETAILS MUD ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = " + Convert.ToInt32(WatchType.Article) + ""
+ " AND MWL.FK_USER_ID = " + userId + " AND MWL.IS_ACTIVE = 1 AND MA.IS_ACTIVE = 1";
// Query for Tips
string selectTips = "SELECT MWL.PK_ID AS PK_ID, 'Tips' + ': ' + MT.TITLE AS TITLE,"
+ " 'Tips.aspx?id=' + CONVERT(VARCHAR, MT.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN M_TIPS MT ON MWL.FK_OBJECT_ID = MT.PK_ID "
+ " INNER JOIN M_USER_DETAILS MUD ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = " + Convert.ToInt32(WatchType.Tip) + ""
+ " AND MWL.FK_USER_ID = " + userId + " AND MWL.IS_ACTIVE = 1 AND MT.IS_ACTIVE = 1";
// Query for IWantINeed
string selectIWantINeed = "SELECT MWL.PK_ID AS PK_ID, 'IWantINeed' + ': ' + MWN.TITLE AS TITLE,"
+ " 'IWantINeed.aspx?id=' + CONVERT(VARCHAR, MWN.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN M_I_WANT_I_NEED MWN ON MWL.FK_OBJECT_ID = MWN.PK_ID "
+ " INNER JOIN M_USER_DETAILS MUD ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = " + Convert.ToInt32(WatchType.IWantINeed) + ""
+ " AND MWL.FK_USER_ID = " + userId + " AND MWL.IS_ACTIVE = 1";
// Query for PointCAT
string selectPointCAT = "SELECT MWL.PK_ID AS PK_ID, 'PointCAT' + ': ' + MPS.TITLE AS TITLE,"
+ " 'PointCAT.aspx?id=' + CONVERT(VARCHAR, MPS.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN M_POINTCAT_SESSIONS MPS ON MWL.FK_OBJECT_ID = MPS.PK_ID "
+ " INNER JOIN M_USER_DETAILS MUD ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = " + Convert.ToInt32(WatchType.PointCAT) + ""
+ " AND MWL.FK_USER_ID = " + userId + " AND MWL.IS_ACTIVE = 1 AND MPS.IS_ACTIVE = 1";
// Query for Seminar
string selectSeminar = "SELECT MWL.PK_ID AS PK_ID, 'Seminar' + ': ' + MS.TITLE AS TITLE,"
+ " 'Seminar.aspx?id=' + CONVERT(VARCHAR, MS.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN M_SEMINAR MS ON MWL.FK_OBJECT_ID = MS.PK_ID "
+ " INNER JOIN M_USER_DETAILS MUD ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = " + Convert.ToInt32(WatchType.Seminar) + ""
+ " AND MWL.FK_USER_ID = " + userId + " AND MWL.IS_ACTIVE = 1 AND MS.IS_ACTIVE = 1";
// Query for CodeCAT
string selectCodeCAT = "SELECT DISTINCT MWL.PK_ID AS PK_ID, 'Code Review Feedback:"
+ " ' + MUD1.FIRST_NAME + ' ' + MUD1.LAST_NAME AS TITLE,"
+ " 'CodeCatFeedback.aspx?id=' + CONVERT(VARCHAR, MCS.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN M_CODECAT_SESSIONS MCS ON MWL.FK_OBJECT_ID = MCS.PK_ID "
+ " INNER JOIN M_USER_DETAILS MUD ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " INNER JOIN M_USER_DETAILS MUD1 ON MUD1.PK_ID = MCS.REVIEW_MEMBER"
+ " WHERE MWL.OBJECT_TYPE = " + Convert.ToInt32(WatchType.CodeCatFeedback) + ""
+ " AND MWL.FK_USER_ID = " + userId + " AND MWL.IS_ACTIVE = 1 AND MCS.ACTIVE = 1";
// Query for NowShowing
string selectNowShowing = "SELECT MWL.PK_ID AS PK_ID, 'NowShowing' + ': ' + MNS.TITLE AS TITLE,"
+ " 'NowShowing.aspx?id=' + CONVERT(VARCHAR, MNS.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN M_NOW_SHOWING MNS ON MWL.FK_OBJECT_ID = MNS.PK_ID "
+ " INNER JOIN M_USER_DETAILS MUD ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = " + Convert.ToInt32(WatchType.NowShowing) + ""
+ " AND MWL.FK_USER_ID = " + userId + " AND MWL.IS_ACTIVE = 1 AND MNS.IS_ACTIVE = 1";
// Query for QA
string selectQA = "SELECT MWL.PK_ID AS PK_ID, 'Q&A' + ': ' + MQ.TITLE AS TITLE,"
+ " 'QA.aspx?id=' + CONVERT(VARCHAR, MQ.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN M_QA MQ ON MWL.FK_OBJECT_ID = MQ.PK_ID "
+ " INNER JOIN M_USER_DETAILS MUD ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = " + Convert.ToInt32(WatchType.QA) + ""
+ " AND MWL.FK_USER_ID = " + userId + " AND MWL.IS_ACTIVE = 1 AND MQ.IS_ACTIVE = 1";
// Query for Message
string selectMessage = "SELECT MWL.PK_ID AS PK_ID, 'Message' + ': ' + MS.SUBJECT AS TITLE,"
+ " 'Message.aspx?id=' + CONVERT(VARCHAR, MS.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN M_MESSAGE MS ON MWL.FK_OBJECT_ID = MS.PK_ID "
+ " INNER JOIN M_USER_DETAILS MUD ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = " + Convert.ToInt32(WatchType.Message) + ""
+ " AND MWL.FK_USER_ID = " + userId + " AND MWL.IS_ACTIVE = 1 AND MS.IS_ACTIVE = 1";
// Query for Documents
string selectDocuments = "SELECT MWL.PK_ID AS PK_ID, 'Documents' + ': ' + MSV.TITLE AS TITLE,"
+ " 'Document.aspx?id=' + CONVERT(VARCHAR, MSD.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN M_SHARE_DOCUMENT MSD ON MWL.FK_OBJECT_ID = MSD.PK_ID "
+ " INNER JOIN M_USER_DETAILS MUD ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " INNER JOIN M_SHARE_DOC_VERSION MSV ON MSV.FK_DOC_ID = MSD.PK_ID AND MSV.IS_ACTIVE =1"
+ " WHERE MWL.OBJECT_TYPE = " + Convert.ToInt32(WatchType.Document) + ""
+ " AND MWL.FK_USER_ID = " + userId + " AND MWL.IS_ACTIVE = 1 AND MSD.IS_ACTIVE = 1";
// Query for Candidate
string selectCandidate = "SELECT MWL.PK_ID AS PK_ID, 'Candidate' + ': ' + MC.CAND_NAME AS TITLE,"
+ " 'Candidates.aspx?id=' + CONVERT(VARCHAR, MC.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN M_CANDIDATE MC ON MWL.FK_OBJECT_ID = MC.PK_ID "
+ " INNER JOIN M_USER_DETAILS MUD ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = " + Convert.ToInt32(WatchType.Candidate) + ""
+ " AND MWL.FK_USER_ID = " + userId + " AND MWL.IS_ACTIVE = 1";
// Query for Prospect
string selectProspect = "SELECT MWL.PK_ID AS PK_ID, 'Prospect' + ': ' + MP.PROSPECT_NAME AS TITLE,"
+ " 'Prospect2.aspx?id=' + CONVERT(VARCHAR, MP.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN M_PROSPECT MP ON MWL.FK_OBJECT_ID = MP.PK_ID "
+ " INNER JOIN M_USER_DETAILS MUD ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = " + Convert.ToInt32(WatchType.Prospect) + ""
+ " AND MWL.FK_USER_ID = " + userId + " AND MWL.IS_ACTIVE = 1";
// Query for ToolCAT
string selectToolCAT = "SELECT MWL.PK_ID AS PK_ID, 'ToolCAT' + ': ' + MT.TOOL_NAME AS TITLE,"
+ " 'Catalyst/ToolCAT.aspx?id=' + CONVERT(VARCHAR, MT.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN M_TOOLCAT MT ON MWL.FK_OBJECT_ID = MT.PK_ID "
+ " INNER JOIN M_USER_DETAILS MUD ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = " + Convert.ToInt32(WatchType.ToolCAT) + ""
+ " AND MWL.FK_USER_ID = " + userId + " AND MWL.IS_ACTIVE = 1 AND MT.IS_ACTIVE = 1";
string selectLearningMatter = "SELECT DISTINCT MWL.PK_ID AS PK_ID, 'Learning Matter: ' + KMLM.TITLE AS TITLE,"
+ " 'KLMS/LearningMatterView.aspx?id=' + CONVERT(VARCHAR, KMLM.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN KLMS_M_LEARNING_MATTER KMLM"
+ " ON MWL.FK_OBJECT_ID = KMLM.PK_ID INNER JOIN M_USER_DETAILS MUD"
+ " ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = 505 AND MWL.FK_USER_ID = " + userId + " AND"
+ " MWL.IS_ACTIVE = 1 AND KMLM.IS_ACTIVE = 1";
// Query for Questions
string selectQuestions = "SELECT DISTINCT MWL.PK_ID AS PK_ID, 'Questions: ' + CONVERT(VARCHAR(400),"
+ " [QUESTION]) AS [TITLE],"
+ " 'KLMS/Question.aspx?id=' + CONVERT(VARCHAR, KMQ.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN KLMS_M_QUESTIONS KMQ"
+ " ON MWL.FK_OBJECT_ID = KMQ.PK_ID INNER JOIN M_USER_DETAILS MUD"
+ " ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = 510 AND MWL.FK_USER_ID = " + userId + " AND"
+ " MWL.IS_ACTIVE = 1 AND KMQ.IS_ACTIVE = 1";
// Query for Test
string selectTest = "SELECT DISTINCT MWL.PK_ID AS PK_ID, 'Tests: ' + KMT.TITLE AS TITLE,"
+ " 'KLMS/Test.aspx?id=' + CONVERT(VARCHAR, KMT.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN KLMS_M_TESTS KMT"
+ " ON MWL.FK_OBJECT_ID = KMT.PK_ID INNER JOIN M_USER_DETAILS MUD"
+ " ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = 515 AND MWL.FK_USER_ID = " + userId + " AND"
+ " MWL.IS_ACTIVE = 1 AND KMT.IS_ACTIVE = 1";
// Query for Course
string selectCourse = "SELECT DISTINCT MWL.PK_ID AS PK_ID, 'Courses: ' + KMC.TITLE AS TITLE,"
+ " 'KLMS/Course.aspx?id=' + CONVERT(VARCHAR, KMC.PK_ID) AS OBJECTURL"
+ " FROM M_WATCHLIST MWL INNER JOIN KLMS_M_COURSES KMC"
+ " ON MWL.FK_OBJECT_ID = KMC.PK_ID INNER JOIN M_USER_DETAILS MUD"
+ " ON MUD.PK_ID = MWL.FK_USER_ID AND MUD.ACTIVE = 1"
+ " WHERE MWL.OBJECT_TYPE = 500 AND MWL.FK_USER_ID = " + userId + " AND"
+ " MWL.IS_ACTIVE = 1 AND KMC.IS_ACTIVE = 1";
//************************************************************************************************
string orderQuery = " ORDER BY " + GridViewSortExpression + " " + GridViewSortDirection;
//For All
if (ddlTypes.SelectedValue == "10")
{
selectStatement = selectArticle + " UNION " + selectTips + " UNION " + selectIdea
+ " UNION " + selectIWantINeed + " UNION " + selectPointCAT + " UNION " + selectSeminar
+ " UNION " + selectCodeCAT + " UNION " + selectNowShowing + " UNION " + selectQA
+ " UNION " + selectMessage + " UNION " + selectDocuments + " UNION " + selectCandidate
+ " UNION " + selectProspect + " UNION " + selectToolCAT;
Can anyone please help me....
Pretty large query. I would add a breakpoint(F9) inside the if and watch the selectStatement; copy the query from there and into my sql editor, and then run/fix it from there.
It seems you are missing some space, or column in the UNION statements.