I'm trying to query the Windows Search 4.0 using sql. The property
of interest for me is: System.Search.QueryFocusedSummary.
I'm trying to read this property from the SystemIndex. I get a "column does not exist" error message. I am able to read other columns such as: System.Search.AutoSummary.
I am using the Microsoft Windows Search 3.x SDK download
(Windows.Search.Interop.dll) on a Windows 7 operating System and Windows
Search 4.0.
My query is:
SELECT TOP 25 System.QueryFocusedSummary From SystemIndex where
CONTAINS('microsoft') ORDER BY System.ItemDate DESC
How can I get the query working with System.Search.QueryFocusedSummary?
The code is as follows:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Security.Permissions;
using System.Text;
using Microsoft.Search.Interop;
namespace QueryFocusedSummaryTest
{
class Program
[Stathread]
static void Main(string[] args)
{
string sqlQuery = "select top 25 System.Search.QueryFocusedSummary from SystemIndex where contains('microsoft') order by System.ItemDate DESC";
CSearchManager manager = new CSearchManager();
ISearchCtalogManager catalogMaager = manager.GetCatalog("SystemIndex");
ISearchQueryHelper queryHelper = catalogManager.GetQueryHelper();
using (System.Data.OleDb.OleDbConnection conn = new OleDbConnection(queryHelper.ConnectionString))
{
conn.Open();
using (OleDbCommand command = new OleDbCommand(sqlQuery, conn))
{
OleDbDataAdapter ds = new OleDbDataAdapter(command);
DataSet ds = new DataSet();
ds.Fill(ds);
command.ExecuteNonQuery();
//By now it has thrown the exception saying that the column is not found.
}
}
}
}
Here is a link about columns available for oledb interface:
https://web.archive.org/web/20120615190325/http://www.ariankulp.com/downloads/WindowsShellOLEProperties.txt
Seems System.Search.QueryFocusedSummary is not exposed, while System.Search.AutoSummary is. Maybe that's why you can't get the column.
Related
Just started using windows 11 and installed Oracle drivers for 32Bit and 64Bit, wrote program using C# to fetch data from Oracle database.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Data.Odbc;
using System.Data;
using System.Data.SqlClient;
namespace ApexAutoEmailConsol
{
static class ServiceLog
{
static String connectionString = "Dsn=Prod21_32;uid=ebseb;pwd=ebseb";
static string strQuery = string.Empty;
public static string OutstandingInvoices()
{
try
{
OdbcConnection oCon = new OdbcConnection();
oCon.ConnectionString = connectionString;
oCon.Open();
DataTable dtSales = new DataTable();
strQuery = "SELECT * from apps.org_organization_definitions HO";
// if I run above query in Toad it's giving result.
OdbcDataAdapter myAdp = new OdbcDataAdapter(strQuery, oCon);
myAdp.Fill(dtSales);
//Adapter not filling data to the datatable.
if (dtSales.Rows.Count <= 0)
{
return "";
}
return strReturn;
}
catch (Exception Ex)
{
WriteErrorLog(Ex.ToString());
return "";
}
}
}
When I copy strQuery and run on Toad, getting result but datatable is still empty.
What is the problem? The same code is working perfect on my Windows10 machine.
UnCOMMITted data is only visible within the session that created it (and will ROLLBACK at the end of the session if it has not been COMMITted). If you can't see the data from another session (C#) then make sure you have issued a COMMIT command in the SQL client (Toad).
If you have issued a COMMIT and still can't see the data then make sure that both the SQL Client (Toad) and the C# program are connecting to the same database and are querying the same user's schema of that database.
It's very unique problem, I had it around 2 years ago with my another machine, where I was not able to get some query result in Toad. Some queries are working but some of with specific table in joing was giving empty result. That time I added following language setting in my environment variable and was worked.
NLS_LANG = American_America.UTF8
Used same in my new machine and now am getting result with Visual Studio 2022.
I am trying to connect to a database in C# and bring up certain data points. The database has numerous columns and tables and I simply want to display them in the console using Writeline(). Below is what I have so far. The code runs without error but does not display anything either.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data.Sql;
namespace SQLIntro
{
class Program
{
static void Main(string[] args)
{
using (SqlConnection connection = new SqlConnection("Server=[SQ_SIXTEEN];Database=[PocketCentral];User ID=[un];Password=[pw];Trusted_Connection=true"))
{
connection.Open();
using (SqlCommand command = new SqlCommand("SELECT * FROM tbl_Terminal", connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
Console.WriteLine(reader.GetValue(i));
}
Console.WriteLine();
}
}
}
}
}
}
}
The one thing is where the column info would go...The SQL command? or in the while loop?.
That code would actually throw an exception. You have surrounded the names with brackets in your connection string which would cause the connection to fail. Change it to:
using (SqlConnection connection = new SqlConnection("Server=SQ_SIXTEEN;Database=PocketCentral;Trusted_Connection=true"))
Note that when Trusted_Connection is true (windows authentication) you don't use UserID and Password.
EDIT: Additional notes.
You would normally know your data content (your columnname and types). From SQL viewpoint it is suggested that you should list all your columns. ie: Instead of simply using "select *" use something like "select firstName, lastName, ... from ...".
As per the reader, instead of reader.GetValue[i] you use reader[index] and cast the type to what it should be like:
(int)reader[0]
(DateTime)reader["OrderDate"]
Integer indexing is faster but depends on column position where string indexing with column name is more readable.
EDIT2: Don't skip looking into LINQ. It is easier IMHO.
I am looking to use the SQL Data adapter feature inside of MVC to display the results from a query string inside of my project. I'm new to using the sql adapter feature but I would like to get used to it. Simply put, I need to know what to put in my controller, and if i need to create a model, and what to put in my view.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace NewHoyaIntranet.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
DataSet data;
DataTable table;
using (SqlConnection connection = new
SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HUT"]
.ConnectionString))
{
connection.Open();
SqlCommand select = new SqlCommand("SELECT * FROM HUT.dbo.XREF_HIOI_LensStyle_HTL", connection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = select;
data = new DataSet();
adapter.Fill(data, "HUT.dbo.XREF_HIOI_LensStyle_HTL");
table = data.Tables[0]; //is the [0] really correct?
}
return View(/* Right now nothing is returning in any view/ how do i tie the view in? */);
}
}
}
I have a table with columns below,
SALES_ORDERS.ORDER_SLIP.NUMBER|SALES_ORDERS.ORDER_SLIP.DATE|SALES_ORDERS.ORDER_SLIP.ARP_CODE
and the XML output I need to have is like below
<SALES_ORDERS>
<ORDER_SLIP>
<NUMBER>TEST</NUMBER>
<DATE>02.09.2014</DATE>
<ARP_CODE>CARI1</ARP_CODE>
</ORDER_SLIP>
</SALES_ORDERS>
I need to create the xml according to column name which include full path way from the top.
How can I achive such an XML file from such a table? I can use LINQ if it is necessary but I am not sure how to do it?
Too Easy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
string SQL = "Enter Your SQL Select string here";
string connStr = "Enter You connection string here";
SqlDataAdapter adapter = new SqlDataAdapter(SQL, connStr);
DataSet ds = new DataSet();
adapter.Fill(ds);
ds.DataSetName = "SALES_ORDERS";
ds.WriteXml(FILENAME, XmlWriteMode.WriteSchema);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Web;
namespace Database_Updation
{
class Program
{
static void Main(string[] args)
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDbConn1"].ToString());
SqlCommand cmd = new SqlCommand("SELECT [GUID] FROM [Source].[dbo].[Source_User]", cn);
cn.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
rdr.Read();
Response.Write(rdr[0].ToString()); //read a value
}
}
}
I am getting error The name 'Response' does not exist in the current context
Try to Use
Console.Write(rdr[0].ToString()); //Write a value
Instead of
Response.Write(rdr[0].ToString()); //Write a value
Hopefully it helps
From you code it is console application than dont use response use and also check datareader having data
if(rdr.Read())
Console.Writeln(rdr[0].ToString());
Response is the object use in Web application, you will get this object in asp.net web application if you like to do so create web applciation not console application... you need to read difference between console and web asp.net application
1st Check For Reference System.Web.dll added or Not
And
try
System.Web.HttpContext.Current.Response.Write(rdr[0].ToString());