views:

39

answers:

2

Hey All,

I am using WinForms & C# to access a SQL Server 2008 on my site which's hosted by winhost.com.

I am using the following code to connect to the database, which I figured out for myself:

try
{
    SqlConnection scon = new SqlConnection(
        "My ConnectionString Info is in here.");
    scon.Open();
    MessageBox.Show(scon.Database);
    cd = true;
}
catch (Exception exception)
{
    MessageBox.Show(exception.Message + "\n" + exception.StackTrace);
}

And it connects to the database perfectly everytime. So, what I anm having trouble doing is (My database on the winhost servers is blank.) adding rows and columns to it, so i can add info later... I would like to use LINQ for this.

I have seen so many tuts online but they all seem so geared towards using a local database and then uploading it! Or using a service! But all I want to do is simply establish a connection, and send a command, something like so:

  • Establish Connection with Remote SQL Server.
  • Add Rows/Columns.
  • Terminate Connection.

...And at a later point:

  • Establish connection.
  • Do a tiny search for something in Row X.
  • Get value of Match in Row X.
  • Terminate Connection.

I would really appreciate your help on this. I know it can be done. I know I've seen articles on this before but it was last year and I didn't need to access a database back then.

MSDN, WindowsCLient and Google have proved to be useless when trying to get the information that I require this time.

Thank you

+2  A: 

I think you are going to have to execute SQL DDL (CREATE TABLE etc) using the DataContext ExecuteCommand.

Cade Roux
Hmmm, sounds like fun. Thank you Cade. :)
lucifer
+1  A: 

Generally, in most applications, you rarely need to change the database's schema (in other words, its structure) programmatically.

You usually do it at design-time using tools like SQL Server Management Studio.

Winhost.com probably provides online tools through their admin-interface or software downloads to do this...

Kharlos Dominguez
John K
lucifer