Showing the output query? - c#

I'm trying to show the output of the query SELECT * FROM phpbb_topics
I'm running this from a C# console app, using the MySql connector api.
The query works fine when I run it phpmyadmin, and gives me a list of forum topics.
When I run it in the C# app remotely though, it doesn't seem to do anything.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql;
using MySql.Data;
namespace SqlConsoleSlr
{
class Program
{
static void Main(string[] args)
{
MySql.Data.MySqlClient.MySqlConnection mycon =
new MySql.Data.MySqlClient.MySqlConnection(GetConnectionString());
Console.WriteLine(GetConnectionString());
if (mycon.State != System.Data.ConnectionState.Open)
try
{
mycon.Open();
Console.WriteLine("we're in");
}
catch (System.Data.SqlClient.SqlException ex)
{
Console.WriteLine(ex);
}
MySql.Data.MySqlClient.MySqlCommand msc = new MySql.Data.MySqlClient.MySqlCommand("SELECT * FROM `phpbb_topics` ");
Console.WriteLine("completed"); /// gets to here, but doesn't show output of msc
Console.ReadLine();
}
public static string GetConnectionString()
{
string hostname = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;";
string username = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx;";
string dbname = "xxxxxxxxxxxxxxxxxxxxxxxx;";
string password = "xxxxxxxxxxxxxxxxxxxxxxxxxxx;";
string s = "Server=" + hostname + "User=" + username + "Database=" + dbname + "Password=" + password;
return s;
}
}
}
Is there some method I need to call on the query object?
The only one I could find is msc.BeginExecuteReader();, but that doesn't seem to change the execution either.

You will need to create a MYSQL Data Reader object.
MySql.Data.MySqlClient.MySqlDataReader read = msqlCommand.ExecuteReader();
and then you can output the records after you read.read() all of the records.

You have to create an object of MySQL Data Reader then execute the command.
MySql.Data.MySqlClient.MySqlCommand msc = new MySql.Data.MySqlClient.MySqlCommand("SELECT * FROM `phpbb_topics` ");
MySql.Data.MySqlClient.MySqlDataReader read = msqlCommand.ExecuteReader();
if(read != null)
{
//Sample output
while (read.Read())
{
int TopicID = Convert.ToInt32(read["Topic_ID"]);
string TopicName = Convert.ToString(read["Topic_Name"]);
Console.WriteLine(TopicID.ToString() + " : " + TopicName);
}
}

Related

C# creating a database class

i want to create a class that handles all my Database-Stuff so i started with this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
namespace Server
{
class Database
{
private MySqlConnection connection;
private string server;
private string database;
private string uid;
private string password;
public Database()
{
server = "localhost";
database = "mydb";
uid = "root";
password = string.Empty;
string connectionString = "SERVER=" + server + ";" + "DATABASE = " + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
connection = new MySqlConnection(connectionString);
}
public bool OpenConnection()
{
try
{
connection.Open();
return true;
} catch(MySqlException e)
{
switch (e.Number)
{
case 0:
// Cannot connect to server
break;
case 1045:
// Invalid username / password
break;
}
return false;
}
}
private bool CloseConnection()
{
try
{
connection.Close();
return true;
} catch(MySqlException e)
{
// ex.message
return false;
}
}
}
}
But i don't know how i should handle inserts, updates and selects that they are dynamic to usw. I want to insert strings, dates and integers.. what is the best solution to create an insert, update and select function that can be used from everywhere?
You have two options.
A) Make methods for every possible Select/Insert/Update/Delete within the Database class
or
B) Make a generic Select and Insert/Update/Delete method which takes an sql query (string) and array/list of SqlParameter and then this data is passed to the functions from another class
The Select method should return a DataTable and the Insert/Update/Delete method could return a value to determine success
Personally I much prefer option B.

Only one record written to sql server + combobox not refreshed

I'm new to .net programming and I have a problem writing intput from a form to sql server. Only one record gets written to the database, for the other records it's says "Data not written to database.". Also my cmbbox is not updated after the data is written to the database, though I run method UpdateInitialWeek().
I don't want to write 'spaghetti code' and would love my program to be a structured one. So any advice is greatly appreciated (I already know it's better to use the Entity Framework to deal with data, something I will learn eventually ;)).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Write_to_database
{
public partial class WriteToDatabase : Form
{
SqlServer sql = new SqlServer();
public WriteToDatabase()
{
sql.OpenSqlConnection();
InitializeComponent();
this.UpdateInitialWeek();
sql.CloseSqlConnection();
}
private void btnWrite_Click(object sender, EventArgs e)
{
WriteToOutput(sql.OpenSqlConnection());
if (txtMilitaryPress.Text != "")
WriteToOutput(sql.InsertToTraining(ConvertDate(dtMilitaryPress.Value), "Military Press", txtMilitaryPress.Text.ToString(), txtRepMilitaryPress.Text.ToString(), cmbMilitaryPress.Text.ToString()));
if (txtDeadlift.Text != "")
WriteToOutput(sql.InsertToTraining(dtDeadlift.Value.ToString(), "Deadlift", txtDeadlift.Text.ToString(), txtRepDeadlift.Text.ToString(), cmbDeadlift.Text.ToString()));
if (txtBenchPress.Text != "")
WriteToOutput(sql.InsertToTraining(dtBenchPress.Value.ToString(), "Bench Press", txtBenchPress.Text.ToString(), txtRepBenchPress.Text.ToString(), cmbBenchPress.Text.ToString()));
if (txtBackSquat.Text != "")
WriteToOutput(sql.InsertToTraining(dtBackSquat.Value.ToString(), "Back Squat", txtBackSquat.Text.ToString(), txtRepBackSquat.Text.ToString(), cmbBackSquat.Text.ToString()));
this.UpdateInitialWeek();
WriteToOutput(sql.CloseSqlConnection());
}
//Write output to textbox
public void WriteToOutput(string output)
{
this.txtOutput.AppendText(output + Environment.NewLine);
}
//Convert date for sql server
public string ConvertDate(DateTime date)
{
return date.ToString("MM/dd/yyyy");
}
//Update comboboxes to set right training week
public void UpdateInitialWeek()
{
this.cmbBackSquat.Text = CheckWeek(sql.GetDataTraining("Back Squat"));
this.cmbBenchPress.Text = CheckWeek(sql.GetDataTraining("Bench Press"));
this.cmbDeadlift.Text = CheckWeek(sql.GetDataTraining("Deadlift"));
this.cmbMilitaryPress.Text = CheckWeek(sql.GetDataTraining("Military Press"));
}
//Training week +1 except for week 4 --> back to 1
public string CheckWeek(string trainingWeek)
{
int trWeek = Int32.Parse(trainingWeek);
if (trWeek == 4)
trWeek = 1;
else
trWeek += 1;
return trWeek.ToString();
}
}
public class SqlServer
{
SqlConnection con = new SqlConnection("Data Source=WINSERVER;Initial Catalog=TRAINING;Integrated Security=SSPI;");
public string OpenSqlConnection()
{
try
{
con.Open();
return "Connection to: " + "'Data Source=WINSERVER;Initial Catalog=TRAINING;Integrated Security=SSPI;'" + " successful.";
}
catch
{
return "Connection to: " + "'Data Source=WINSERVER;Initial Catalog=TRAINING;Integrated Security=SSPI;'" + " failed.";
}
}
public string CloseSqlConnection()
{
try
{
con.Close();
return "Connection to: " + "'Data Source=WINSERVER;Initial Catalog=TRAINING;Integrated Security=SSPI;'" + " successfully closed";
}
catch
{
return "Connection to: " + "'Data Source=WINSERVER;Initial Catalog=TRAINING;Integrated Security=SSPI;'" + " not closed.";
}
}
public string InsertToTraining(string date, string lift, string weight, string reps, string week)
{
try
{
using (SqlCommand command = new SqlCommand("INSERT INTO LIFT_HISTORY VALUES(#date,#lift,#weight,#reps,#week)", con))
{
command.Parameters.Add(new SqlParameter("weight", weight.ToString())); //SqlDbType.NVarChar
command.Parameters.Add(new SqlParameter("date", date.ToString()));
command.Parameters.Add(new SqlParameter("week", week.ToString()));
command.Parameters.Add(new SqlParameter("reps", reps.ToString()));
command.Parameters.Add(new SqlParameter("lift", lift.ToString()));
command.ExecuteNonQuery();
}
return "Data successfully written to database.";
}
catch
{
return "Data not written to database.";
}
}
public string GetDataTraining(string where)
{
int trainingWeek;
//using (SqlCommand command = new SqlCommand("SELECT WEEK_OF_TRAINING FROM dbo.LIFT_HISTORY WHERE [DATE] = (SELECT MAX([DATE]) FROM dbo.LIFT_HISTORY WHERE LIFT = 'Deadlift') AND LIFT = 'Deadlift')", con))
using (SqlCommand command = new SqlCommand("SELECT WEEK_OF_TRAINING FROM dbo.LIFT_HISTORY WHERE LIFT = '"+ where +"' ORDER BY [DATE] DESC", con))
{
trainingWeek = (Int32)command.ExecuteScalar();
}
return trainingWeek.ToString();
}
}
}
There are some issues with your code, but it's ok for now that you still learning, for example:
public WriteToDatabase()
{
sql.OpenSqlConnection();
InitializeComponent();
this.UpdateInitialWeek();
sql.CloseSqlConnection();
}
should be:
public void WriteToDatabase()
{
sql.OpenSqlConnection();
InitializeComponent();
this.UpdateInitialWeek();
sql.CloseSqlConnection();
}
That's because you're not returning anything, instead of that you shoud to declare the type of variable that you're returning on.
Well first of all I'd like to suggest you to use a layer-oriented coding. For example:
I'll start crating an entity class:
namespace Entities
{
public class LiftingStory
{
public string Weight { get; set; }
public string Date { get; set; }
public string Week { get; set; }
public string Reps { get; set; }
public string Lift { get; set; }
}
}
Then you start creating "Data-Access" Layer
using System.Data;
using System.Configuration;
using Entities;
namespace DataAccess
{
public class DataLiftingStory
{
public bool insertLifting(LiftingStory obj) //correction: should be LiftingStory instead of DataLiftingStory because I'm retrieving a LiftingStory objecto to be proccesed.
{
//we're creating a new connection to Database, but it will need string parameter
//you can get it directly from the connectionstring on the Web.config in this way
// ConfigurationManager.ConnectionStrings["nameParameterOfYourConnString"].ConnectionString
//instead of that I'll do it with a string for making more easier to understand
string connectionString = "Data Source=WINSERVER;Initial Catalog=TRAINING;Integrated Security=SSPI;";
using (SqlConnection connection = new SqlConnection(connectionString))
{
//now I'll create the command
using (SqlCommand command = new SqlCommand())
{
//so now I've to say what type of command I'm making up. In your case is "Text" because you're being explicit with the query
//I suggest you to use stored procedures btw.
command.CommandType = CommandType.Text;
//now the command text will be your query
command.CommandText = "INSERT INTO LIFT_HISTORY VALUES(#date,#lift,#weight,#reps,#week)";
//now we set the parameters
command.Parameters.Add(new SqlParameter("date", obj.Date));
command.Parameters.Add(new SqlParameter("lift", obj.Lift));
command.Parameters.Add(new SqlParameter("weight", obj.Weight));
command.Parameters.Add(new SqlParameter("reps", obj.Reps));
command.Parameters.Add(new SqlParameter("week", obj.Week));
try
{
command.Connection = connection;
command.Connection.Open();
//now we're executing the query and if we get more than 0 that will means that it inserted or modified a row
//then it will return true and going out from method.
if (command.ExecuteNonQuery() > 0)
return true;
}
catch (Exception)
{
//If it fails return false
return false;
throw;
}
finally
{
//then we close the connection
command.Connection.Close();
}
//if not failed but it didn't anything, it will return false
return false;
}
}
}
Now it's the easy part Business.
using System.Web;
using Entities;
using DataAccess;
namespace Business
{
public class BusinessLiftingStory
{
public bool insertLifting(LiftingStory obj)
{
DataLiftingStory dataLifting = new DataLiftingStory();
dataLifting.insertLifting(obj);
}
}
}
So the last step is to fill the object in the "View-layer" and call the method from Business:
LiftingStory obj = new LiftingStory();
obj.Weight = string.Empty;
obj.Date = string.Empty; //put values from comboBoxes
obj.Reps = string.Empty;
obj.Lift = string.Empty;
obj.Week = string.Empty;
BusinessLiftingStory busObj = new BusinessLiftingStory();
busObj.insertLifting(obj);
Combo boxes are not refreshing data because the DataBind() method, dont forget in the moment when you want to "redraw" your comboBox you'll have to set DataSource = null then get the datasource again and then dataBind.
use a method Init() for that if you want.
private void Init()
{
cmbWeight.DataSource = null;
cmbWeight.DataSource = //new Datasource
//dont forget to set the values and text fields
cmbWeight.DataBind();
}
In that way you'll have a order in your code, , I hope it would help you.
Greetings :)
PS: sorry for the extended answer.
maybe try printing out the exception details either to your return string or console, etc.
instead of
catch
{
return "Data not written to database.";
}
..
catch( Exception ex )
{
return "Data not written to database." + ex.Message;
}
..
https://msdn.microsoft.com/en-us/library/system.exception.message(v=vs.110).aspx

Appending to File resulting in missing data

I have a script that is connecting to multiple databases and writing a query from each into a text file. However when I run it, I'm not getting the results expected. After some cross checking, it looks like it is writing the same results from the first database query instead of finding new results from the next connection. I inserted an IP string to verify the IPs are being grabbed by the for loop but it seems like I need some way of clearing the reader?
for (int z=0; z<2;z++) {
using (OleDbConnection connLocal = new OleDbConnection("Provider=SAOLEDB;LINKS=tcpip(host=" + ips[z] + ",PORT=2638);ServerName=EAGLESOFT;Integrated Security = True; User ID = dba; PWD = sql"))
try
{
connLocal.Open();
using (OleDbCommand cmdLocal = new OleDbCommand("SELECT tran_num, '" + ips[z] + "', provider_id, amount, tran_date, collections_go_to, impacts, type, '" + clinics[z] + "' AS Clinic FROM transactions WHERE tran_date LIKE '2015-11-23%'", connLocal))
using (StreamWriter sqlWriter = File.AppendText(#"C:\Users\Administrator\Desktop\Clinic.txt"))
{
using (OleDbDataReader readLocal = cmdLocal.ExecuteReader())
{
while (readLocal.Read())
{
sqlWriter.WriteLine("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}",
readLocal.GetValue(0).ToString(),
readLocal.GetValue(1).ToString(),
readLocal.GetValue(2).ToString(),
readLocal.GetValue(3).ToString(),
readLocal.GetValue(4).ToString(),
readLocal.GetValue(5).ToString(),
readLocal.GetValue(6).ToString(),
readLocal.GetValue(7).ToString(),
readLocal.GetValue(8).ToString());
}
readLocal.Close();
}
sqlWriter.Close();
connLocal.Close();
}
}
catch (Exception connerr) { Debug.WriteLine(connerr.Message); }
}
As always, any insight is much appreciated!

Validating Database Input C# Access Oledb

I am very new to C# and need a little bit of help on validating the input that can be added to the access database before it is inserted.
Most of the validations will be if something has not been entered then a message box will appear saying 'nothing entered' or if something needs more characters then 'length too short'. How could i achieve something like this?
Here is my code:
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ClassLibrary;
using System.Data;
namespace ClassLibrary2
{
public class Class1
{
OleDbConnection connection;
OleDbCommand command;
private void ConnectTo()
{
connection = new OleDbConnection(#"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\CMS\CustomerDatabase.accdb;Persist Security Info=False");
command = connection.CreateCommand();
}
public Class1()
{
ConnectTo();
}
public void Insert(Customer p)
{
try
{
command.CommandText = "INSERT INTO CustomerData ([Forename], [Surname], [Email Address], [Home Phone Number], [Mobile Phone Number], [Address], [AreaTown], [County], [Postcode]) VALUES('" + p.Forename1 + "', '" + p.Surname1 + "', '" + p.EAddress1 + "', '" + p.HomePhone1 + "' , '" + p.MobNum1 + "' , '" + p.Address1 + "', '" + p.AreaTown1 + "', '" + p.County1 + "', '" + p.Postcode1 + "')";
command.CommandType = CommandType.Text;
connection.Open();
command.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
if (connection != null)
{
connection.Close();
}
}
}
public List<Customer> FillComboBox()
{
List<Customer> CustomersList = new List<Customer>();
try
{
command.CommandText = "SELECT * FROM CustomerData";
command.CommandType = CommandType.Text;
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Customer p = new Customer();
p.Id = Convert.ToInt32(reader["ID"].ToString());
p.Forename1 = reader["Forename"].ToString();
p.Surname1 = reader["Surname"].ToString();
p.EAddress1 = reader["Email Address"].ToString();
p.HomePhone1 = reader["Home Phone Number"].ToString();
p.MobNum1 = reader["Mobile Phone Number"].ToString();
p.Address1 = reader["Address"].ToString();
p.AreaTown1 = reader["AreaTown"].ToString();
p.County1 = reader["County"].ToString();
p.Postcode1 = reader["Postcode"].ToString();
CustomersList.Add(p);
}
return CustomersList;
}
catch (Exception)
{
throw;
}
finally
{
if (connection != null)
{
connection.Close();
}
}
}
public void Update(Customer oldCustomer, Customer newCustomer)
{
try
{
command.CommandText = "UPDATE CustomerData SET [Forename] = #newCustomer.Forename1, [Surname] = #newCustomer.Surname1, [Email Address] = #newCustomer.EAddress1, [Home Phone Number]= #newCustomer.HomePhone1, [Mobile Phone Number] = #newCustomer.MobNum1, [Address]= #newCustomer.Address1, [AreaTown] = #newCustomer.AreaTown1, [County]= #newCustomer.County1, [Postcode]= #newCustomer.Postcode1 WHERE [ID] = #oldCustomer.Id";
command.Parameters.AddWithValue("#Forename", newCustomer.Forename1);
command.Parameters.AddWithValue("#Surname", newCustomer.Surname1);
command.Parameters.AddWithValue("#Email Address", newCustomer.EAddress1);
command.Parameters.AddWithValue("#Home Phone Number", newCustomer.HomePhone1);
command.Parameters.AddWithValue("#Mobile Phone Number", newCustomer.MobNum1);
command.Parameters.AddWithValue("#Address", newCustomer.Address1);
command.Parameters.AddWithValue("#AreaTown", newCustomer.AreaTown1);
command.Parameters.AddWithValue("#County", newCustomer.County1);
command.Parameters.AddWithValue("#Postcode", newCustomer.Postcode1);
command.Parameters.AddWithValue("#ID", oldCustomer.Id);
command.CommandType = CommandType.Text;
connection.Open();
command.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
if (connection != null)
{
connection.Close();
}
}
}
Thanks for your help, im really struggling
If you want to archive this try to Implement a function that check every validation before you execute the save function
hope following sample function will give you an idea
private bool CheckValidation( )
{
bool returnBool = true;
if ( string.IsNullOrWhiteSpace(txtName.txt) )
{
//Show a label next to you text box
returnBool = false;
}
return returnBool;
}
If your return value is true save the data to data base using SP
Hope this will guide you. for extra information have you aware with SQLHelper class. It will make your life easier, therefore you don't need to implement connection and SP calls every where. if not let me know will send you sample project.
welcome to .NET world
regards,
Pubudu
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ClassLibrary;
using System.Data;
namespace DAL
{
public static class CustomerDAL
{
public static void Insert(Customer p){.......}
public static List<Customer> FillComboBox(){......}
public void Update(Customer oldCustomer, Customer newCustomer){.......}
}
}
----------------------------------------------------
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ClassLibrary;
using System.Data;
namespace BAL
{
public class Customer
{
public int Id {get;set;}
public string Name {get;set;}
.......................
.......................
}
}
------------------------------------------------------
In UI Create a Windows or Web Form and add buttons and textbox and on buttonSave_Click event
If(txtName.Text=="")
{
MessageBox.Show("Some text", "Some title",
MessageBoxButtons.OK, MessageBoxIcon.Error);
txtName.Focus();
}
else
{
//calling BAL
var cus=new Customer{
Name=txtName.Text
}
//Calling DAL
CustomerDAL.Insert(cus);
MessageBox.Show("Information", "Record saved successfully inti the database.",
MessageBoxButtons.OK, MessageBoxIcon.Information);
txtName.tex="";
}
Hope this will help you.
Create a solution,give it a proper name.Then inside the solution create two assembles projects BAL and DAL.If you are still confused about assembles then avoid creating assemblies and following link might help you.
http://www.tutorialized.com/tutorial/3-Tier-Architecture-in-asp.net-using-c/67931
Validation of user input regarding length, patterns, text versus numbers, etc. should be done before your code gets near the data layer.
This is what regular expressions are great at. There is a ton of information on using them, so I won't try to repeat here. Just bingoogle regular expressions and you will find a wealth of info.

Code stops working after convering flat MDB to SQL-linked mdb

I have modified my code to count records in each table inside an mdb file. It works flawlessly, until it hits an MDB file using linked tables, which point to a SQL server. The code cannot be modified to point to the SQL server directly, it is for an in-place software upgrade scenario.
How can I modify this code to work with regular as well as linked tables?
using System;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Diagnostics;
using System.Collections;
using System.Data.Common;
using System.Collections.Generic;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] databases = new string[3];
databases[0] = "data.mdb";
databases[1] = "chunk.mdb";
databases[2] = "transactions.mdb";
DateTime dt = DateTime.Now;
string filename = "Results-" + dt.Hour + "_" + dt.Minute + "_" + dt.Second + ".txt";
System.IO.StreamWriter file = new System.IO.StreamWriter(filename);
foreach(string db in databases)
{
file.WriteLine("##########BEGIN " + db + "##########\r\n");
Console.Write("Processing " + db + " Database . . . ");
string strAccessConn = #"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\financial\" + db;
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
DataTable userTables = null;
DataSet myDataSet = new DataSet();
OleDbConnection conn = new OleDbConnection(strAccessConn);
using (DbConnection connection = factory.CreateConnection())
{
connection.ConnectionString = #"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\financial\DATA\" + db;
string[] restrictions = new string[4];
restrictions[3] = "Table";
try
{
connection.Open();
}
catch
{
Console.WriteLine("Error opening MDB file. Please ensure it is in the correct location");
}
userTables = connection.GetSchema("Tables", restrictions);
}
ArrayList tables = new ArrayList();
for (int i=0; i < userTables.Rows.Count; i++)
tables.Add(userTables.Rows[i][2].ToString());
foreach (string tbl in tables)
{
string queryString = "SELECT COUNT(*) FROM " + "[" + tbl + "]";
OleDbCommand command = new OleDbCommand(queryString, conn);
command.Connection.Open();
try
{
int records = (int)command.ExecuteScalar();
file.WriteLine("{0,-45}" + records,tbl);
}
catch (OleDbException e)
{
Console.WriteLine(e + "OLEDB Exception Occured.");
}
command.Connection.Close();
}
file.WriteLine("\r\n##########END " + db + "##########");
Console.WriteLine("Done!\n");
}
file.Close();
Console.WriteLine(#"All Databases Complete. Press any key to continue...");
Console.Read(); // Press any key to continue...
System.Diagnostics.Process.Start("notepad.exe",filename);
}
}
}
Hi I believe that can't be done with ado.net, I had the same scenario some years ago with ado.net 1. You have to use ADOX.
here is a list of ADOX examples that can be useful
http://allenbrowne.com/func-adox.html
ADOX does not make a difference between table and linked tables. ill take a look to my hard drive and I may post an example later.
you should execute your query with ADOX and you won't have the same problem that you have with ADO.net
You can also do this with DAO.

Categories