在类文件中,我使用csharp在windows应用程序中编写了一个gloabl函数 [英] in class file i written a gloabl function in windows application using csharp

查看:86
本文介绍了在类文件中,我使用csharp在windows应用程序中编写了一个gloabl函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

con = new SqlConnection(connectionstring);





我的代码如下;



My code as follows;

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;


namespace Faculty_Schedule_Time_Table
{

        public class Global_Function
    {

            public SqlConnection con = new SqlConnection();
            private string connectionstring ="Data Source=NARASIMAN;connect timeout=120;initial catalog=HIMT;userid=sa;";

            private SqlCommand cmd;
            private SqlDataReader dr;

            public string error;

            public Global_Function()
            {

            }

            public void BindCon()
            {
                con = new SqlConnection();
                con.ConnectionString = connectionstring;
                con.Open();

            }

            public void insertdata(String SQL)
            {
                try
                {
                    BindCon();
                    cmd = new SqlCommand(SQL, con);
                    cmd.ExecuteReader();
                }
                 catch(Exception e1)
                  {
                   error = e1.Message.ToString();
                  }
            }
            public SqlDataReader ReadSql(string SQL)
            {

            con = new SqlConnection(connectionstring);
            con.Open();
            cmd  = new SqlCommand(SQL,con);
            dr = cmd.ExecuteReader();
            return (dr);
            
        }
           
            public string CntString()
        {
            return connectionstring;
        }
    }
}





当我运行以上内容时,它会显示以下错误,如下所示;



When i run the above it shows the below error as follows;

Keyword not supported: 'userid'.



它显示以下行中的错误,如下所示;


it shows the error in below line as follows;

con = new SqlConnection(connectionstring);



请帮帮我。



我正在使用sqlserver 2000数据库。



如何用户名和sqlserver 2000数据库的密码。



已添加代码块[/编辑]


Please help me.

I am using sqlserver 2000 database.

how to username and password of sqlserver 2000 database.

Code block added[/Edit]

推荐答案

它'不是全局函数 - C#没有全局函数或变量的概念。我建议您查看 static 键盘,这将使这些更容易使用,因为您不需要实例来访问它们。



要摆脱现有问题,您可能需要在userid字样中添加空格:

It''s not a global function - C# has no concept of global functions or variables. I would suggest that you look into the static keyboard which would make these easier to use as you will not need an instance to access them.

To get rid of your existing problem, you will probably need to add a space in teh word "userid":
private static string connectionstring ="Data Source=NARASIMAN;connect timeout=120;initial catalog=HIMT;user id=sa;";



但您可能还会发现需要密码。



尝试建立连接在VS中使用Server Explorer窗格:

1)打开服务器资源管理器。

2)右键单击数据连接并选择添加连接

3)在随后的对话框中,选择您的数据源和数据库,指定安全信息,然后按测试连接按钮。

4)当连接有效时,按确定

5)在服务器资源管理器窗格中突出显示数据库,然后查看属性窗格。将显示连接字符串的工作示例,您可以将其复制并粘贴到您的应用程序或配置文件中。


But you may find you need a password as well.

Try setting up a connection in VS with the Server Explorer pane:
1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.


这篇关于在类文件中,我使用csharp在windows应用程序中编写了一个gloabl函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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