我在javascript中写了我的设计代码我不知道如何在c#中编写数据库连接 [英] i wrriten my design code in javascript i dont know how to write the database connectivity in c#

查看:51
本文介绍了我在javascript中写了我的设计代码我不知道如何在c#中编写数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在javascript中写了我的设计代码我不知道如何在c#

i wrriten my design code in javascript i dont know how to write the database connectivity in c#

推荐答案

中编写数据库连接如果你想从你的应用程序中传递你的数据库c#然后您可以使用ADO.net(.NET框架组件进行数据访问)帮助。有这么多类有两个访问数据库。例如SqlConnection,SqlCommand,SqlDataReader,SqlDataAdapter等用于Sql Server特定组件。代码示例如下:



If you want to communicate your database from your application c#code then you can take ADO.net(.NET framework component for data access) help. There are so many classes are there two access database. For example SqlConnection, SqlCommand, SqlDataReader, SqlDataAdapter etc for Sql Server specific component. Code sample as follows:

string connectionString = "Data Source=192.168.1.4; Initial Catalog=your_databaseName; User Id=sa; Password=****";
            using(var conn = new System.Data.SqlClient.SqlConnection(connectionString))
            {
                using(System.Data.SqlClient.SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT Id, Name FROM MyTable";
                    cmd.CommandType = CommandType.Text;

                    cmd.Connection.Open();
                    System.Data.SqlClient.SqlDataReader dataReader = cmd.ExecuteReader();
                }
            }

connectionString是数据库所在的实际数据库路径和身份验证信息。



来自你的客户端javascript函数你无法直接访问数据库。如果你需要,那么你可以编写webserivice / wcf / webapi然后从你的javascript函数中调用带有ajax调用的web服务。

connectionString is the actual database path where your database is located and authentication information.

From your client side javascript function you can not access database directly. If you need so then you can write webserivice/wcf/webapi and then from your javascript function you will call that webservice with ajax calling.


这篇关于我在javascript中写了我的设计代码我不知道如何在c#中编写数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆