本文介绍了是否必须在我的计算机中安装C#才能访问SQL数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

你好朋友,

我正在尝试编写对SQL感兴趣的代码。我不会使用SQL IDE这就是为什么我想知道我是否可以访问数据库,除非SQL安装。我会只是运行C#代码,我不想在机器中安装SQL服务器,因为可能5年后它可能是适应问题。



什么我试过了:



Hello friends,
I am trying to write codes that is interested with SQL.I won't use the SQL IDE this is why I wonder if I can access database unless SQL installed.I will just run the C# codes ,I wouldn't like to install SQL server in the machine because maybe 5 five years later it can be adaptation problem.

What I have tried:

private void button1_Click(object sender, EventArgs e)
        {
            if (sqlConnection.State == ConnectionState.Closed)
            {
                label61.Text = DateTime.Now.ToString();
                sqlConnection.Open();
                SqlCommand sqlCommand = new SqlCommand("Insert into ContaVarlık([Parça Varlığı],Tarih) VALUES ('" + "OK" + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')", sqlConnection);
                sqlCommand.ExecuteNonQuery();
                sqlCommand.Dispose();
                sqlConnection.Close();
            }
        }
        //********************************************************************************************************************//
        private void button2_Click(object sender, EventArgs e)
        {
            string command = "if exists(select * from sys.tables where name like 'ContaVarlık') drop table ContaVarlık " +
                "create table ABC(" +
                "OgrNo varchar(4))";

            if (sqlConnection.State == ConnectionState.Closed)
            {
                SqlCommand sqlCommand = new SqlCommand(command, sqlConnection);
                sqlConnection.Open();
                sqlCommand.ExecuteNonQuery();
                sqlConnection.Close();
            }
        }

推荐答案

if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'ContaVarlık' AND TABLE_SCHEMA = 'dbo')
    drop table dbo.ContaVarlık;

包含连接的第一段代码也不需要连接 - 它可以ld只是

Also the first bit of code that contains the concatenation does not need the concatenation - it could just be

Insert into ContaVarlık([Parça Varlığı],Tarih) VALUES ('OK',GetDate())




这篇关于是否必须在我的计算机中安装C#才能访问SQL数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 23:12