开发者

Sending command to SQL Database

开发者 https://www.devze.com 2023-01-09 02:26 出处:网络
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:

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


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


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消