|
Take a look at: HOW TO: Build a Connection String Programmatically in ADO.NET by Using Visual C# .NET[^]
For a more reusable sample, try this code:
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using ADODB;
using MSDASC;
public sealed class DataLinkDialog : CommonDialog
{
private string _connectionString;
public DataLinkDialog(string connectionString)
{
_connectionString = connectionString;
}
public DataLinkDialog()
{
_connectionString = string.Empty;
}
public string ConnectionString
{
get { return _connectionString; }
set { _connectionString = value; }
}
public override void Reset()
{
_connectionString = string.Empty;
}
protected override bool RunDialog(IntPtr hwndOwner)
{
DataLinks dl = new DataLinksClass();
try
{
if (null == _connectionString || 0 == _connectionString.Length)
{
object ret = dl.PromptNew();
if (null == ret)
{
return false;
}
else
{
_connectionString = ((ADODB._Connection)ret).ConnectionString;
Marshal.ReleaseComObject(ret);
return true;
}
}
else
{
Connection cn = new ConnectionClass();
object ocn = cn;
try
{
cn.ConnectionString = _connectionString;
if (dl.PromptEdit(ref ocn))
{
_connectionString = cn.ConnectionString;
return true;
}
else
{
return false;
}
}
finally
{
Marshal.ReleaseComObject(cn);
}
}
}
finally
{
Marshal.ReleaseComObject(dl);
}
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
I am working on optimizing an application that uses stored procedures heavily.
Almost every procedure starts with:
SET DATEFORMAT dmy which causes a recompilation during the procedure execution. It takes about 5 seconds.
Is there any way to set the dmy as a default setting on the startup of the application? Any other ideas how to solve this problem?
I use MS SQL Server 2000.
modified on Monday, August 30, 2010 6:32 AM
|
|
|
|
|
I know Oracle has a default date format that is set as part of the database configuration. I would suspect the same is true for SQL Server, but I'm not up on it. Either I try to avoid depending upon defaults when writing a stored procedure. In the long run, you will have less headaches if within your procedure, you translate between the strings and date types using explicit formats. For example;
convert a date to a string
to_char(some_date_field,'dmy')
convert a string to a date
to_date(some_char_field,'dmy')
Chris Meech
It's much easier to get rich telling people what they want to hear. Christopher Duncan
I can't help getting older, but I refuse to grow up. Roger Wright
I've been meaning to change my sig. Thanks! Alvaro Mendez
We're more like a hobbiest in a Home Depot drooling at all the shiny power tools, rather than a craftsman that makes the chair to an exacting level of comfort by measuring the customer's butt. Marc Clifton
|
|
|
|
|
Chris Meech wrote:
In the long run, you will have less headaches if within your procedure, you translate between the strings and date types using explicit formats
I thought about it. However, the problem is that my task is to optimize a system that uses many stored procedures written by different people. I would have to go through all the procedures (I haven't written any of them!) and find places where using converting functions is necessary.
Sounds like a nightmare to me.
modified on Monday, August 30, 2010 6:32 AM
|
|
|
|
|
I'd recommend using invariant date formats throughout: yyyymmdd.
You could also set the default language database option - see this article in Books Online[^] for more details.
|
|
|
|
|
Mike Dimmick wrote:
You could also set the default language database option
Great idea!
I did not know it sets not only the language but also the date format.
Thanks.
modified on Monday, August 30, 2010 6:33 AM
|
|
|
|
|
Can somebody recommend a SQL data structure that would "describe" a simple HTML table as shown below?
Section 1 | Section 2 | Section 3 | Section 4 |
|
|
|
|
|
Think about what the entities are and their relationship. Also think about what attributes each entity has.
From the example given:
Table, Tr and Td are the entities.
Table is the parent of Tr
Tr is the parent of Td
Td has the attribute colspan
Td has the attribute InnerText (i.e. "Section 1", "Section 2" etc.)
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
Enumerators in .NET: See how to customise foreach loops with C#
|
|
|
|
|
Hello
I have a problem, im running mysql and mysqldump command-line exes from my application. i need: to know if the operation succeded from my application, is there a way to know the last error ocurred?
other quertion: i used the --html option, but the output is still plain text, any ideas?
here is one of the commands i execute:
mysql --host=laura --user=avs_db_user --password=faceshape --verbose --html --database=avs_db -e " source c:\backup\aaa.sql" > output.htm
thanks
|
|
|
|
|
In SQLServer when I want column that start between range of a to b I use this syntax:
column LIKE '[a-b]%'
But it seems that it does not worl correctly in Access. How should I get that query in Access?
Mazy
No sig. available now.
|
|
|
|
|
try:
column LIKE '[a-b]*'
|
|
|
|
|
Nope,I found it some days before, MS ACCESS does not support range for LIKE. I should use it seprately:"[a]% AND [b]%" And I donna why '%' works but '*' doesn't work cause as you said '*' is correct. Any way, thanks for your reply.
Mazy
No sig. available now.
|
|
|
|
|
Mazdak wrote:
MS ACCESS does not support range for LIKE.
how comes ?
open the sample database northwind (comes with access) and try this query :
SELECT lastname
FROM Employees
where lastname like '[a-d]*'
results :
Last Name:
Davolio
Buchanan
Callahan
Dodsworth
|
|
|
|
|
Yes,its srtange for me too,but that really happend,maybe because my database contain Farsi charachter and windows always have problem with Farsi charachters.
Mazy
No sig. available now.
|
|
|
|
|
1. I've created a a view based on table "Orders".
2. I've been assigned role="dlladmin", let's say my login="Tom"
3. I granted jane (public) access privilege by:
grant select on vwOrders to jane
4. server admin "sa" transfered the view to dbo
sp_changeobjectowner 'Tom.vwOrders', 'dbo'
5. I checked Jane's access privilege to vwOrders by:
5a. From Jane's account:
select * from vwOrders
result: NO problem, jane can access the view. OKAY.
5b. Enterprise Manager: Choose the table, select properties>Permission
result: Jane was not assigned SELECT permission??
MY QUESTION: WHY? Is it a bug in Enterprise Manager? That privileges assigned before the view was transfered is not reflected in choose table>Properties>Permission?
Thanks in advance.
|
|
|
|
|
Hello fellow friends,
I am working on a project that needs to compare a users input string with the rest of the records in the table (MS-SQL).
E.g : User enters a string "I love .net"
Other entries in the database :
1. "I love ADO.net"
2. "I love ADO"
3. "No love"
The user entered string is to be compared with the rest of the records and displayed in % (no. of words found matching, taking users string as 100%) for each record.
For above 3 records : 1. 100%, 2. 67% 3. 34% (approximately)
The project is in C#.
What i need is a function/s. or a sql procedure or...any code thats can solve my problem.
"Merry Christmas to All"
A-La
|
|
|
|
|
I am trying to retriev table in excel file using following code, but I get connection error like : Microsoft.Jet.OleDB 4.0 not registered on local machine or installbale ISAM not found. I am using Windows 2000 Adevance server and Visual Studio.Net 2003 and FrameWork 1.1 on my computer. Can any one please help?:
===========
CODE SNIPPET
============
string FileNam = "C:\\ExcelToXml\\ExcelInfo.xml";
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB 4.0;Data Source=EXCEL.C:\\ExcelToXml\\foodgroup.xls;Extended Properties=Excel 8.0;";
OleDbConnection Conn = new OleDbConnection(strConn);
try
{
Conn.Open();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
//You must use the $ after the object you reference in the spreadsheet
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$]", Conn);
OleDbDataAdapter objAdapter = new OleDbDataAdapter();
objAdapter.SelectCommand = objCmdSelect;
DataSet myDataSet = new DataSet();
try
{
objAdapter.Fill(myDataSet, "ExcelInfo");
Conn.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
myDataSet.WriteXml(FileName);
}
Bharat Gadhia
|
|
|
|
|
Bharat Gadhia wrote:
strConn = "Provider=Microsoft.Jet.OLEDB 4.0;Data Source=EXCEL.C:\\ExcelToXml\\foodgroup.xls;Extended Properties=Excel 8.0;";
does not look correct.
try:
strConn = "Provider=Microsoft.Jet.OLEDB 4.0;Data Source=C:\\ExcelToXml\\foodgroup.xls;Extended Properties=Excel 8.0;";
(no "EXCEL." before path to datasource).
Genius may have its limitations, but stupidity is not thus handicapped. - Elbert Hubbard
|
|
|
|
|
Hi Graham,
Thank you so much for your reply. I did try using:
strConn = "Provider=Microsoft.Jet.OLEDB 4.0;Data Source=C:\\ExcelToXml\\foodgroup.xls;Extended Properties=Excel 8.0;";
Problem persists. In fact I tried various ways to write connection string and use it, but I get the same error mesages. I have on my machine entire MS Office suit installed.
With best regards
Bharat Gadhia
Help is always welcome
|
|
|
|
|
Missing . - the name of the provider is 'Microsoft.Jet.OLEDB.4.0'.
|
|
|
|
|
Thanks for your suggestion. I did try that but somehow problem persisits.
|
|
|
|
|
I have already used ADO with Visual C++.
I also used ADO.NET with Visual C#.
My questions are :
-Is it possible to use ADO.NET with Visual C++ in the same one uses ADO (I could not find any sample with the DataSet in MSDN)?
- If yes can you show me an example?
Thanks for any answer!
|
|
|
|
|
I'm a beginner in the field of Oracle. I want to know the way on how to make the connection to Oracle with ADO format.I have no idea about all the store procedures... The only thing i experienced is connecting to MS Access with ADO(ODBC). Is it the similar way to do so with this Oracle????
wb
|
|
|
|
|
Hello,
I want to learn ADO.NET. I am an intermediate level programmer and am currently learning C#. Can anyone suggest a good book to purchase to learn ADO?
Thanx for the help.
-Flack
|
|
|
|
|
Hello again...
Well the book I suggested for ASP.NET also gives a little introduction to ADO.NET as well (in the context of a Web Application). But once your past that, for a more in depth look, go for "Professional ADO.NET programming" published by Wrox Press. Although I ought to warn you that the content is quite dense if you have no experience what so ever.
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
Enumerators in .NET: See how to customise foreach loops with C#
|
|
|
|