用于DataGrid的C#Oracle连接字符串

C# Oracle connection string for DataGrid
2021-02-23
  •  译文(汉语)
  •  原文(英语)

当我通过连接字符串将数据集导入到应用程序时,我选择"从连接字符串中不排除信息.我将在应用程序中设置此信息".

现在,当我编译表单时,在DataGrid中什么也看不到,我必须在我的应用程序中将连接放置到connet吗?

我现在有:

 public Form1()
        {
            InitializeComponent();

            using (OracleConnection con = new OracleConnection("Data Source=localhost;Persist Security Info=True;User ID=martynas;Password=xxxxxxx;Unicode=True"))
            {
                try
                {
                    con.Open();
                    OracleCommand cmd = new OracleCommand();
                    cmd.Connection = con;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

此连接是打开的,但是DataGridView仍然不显示任何记录.我认为也许我将连接方法错误?

解决过程1

您没有将OracleCommand连接到任何东西.您创建了它,但是当它超出范围时,它就不存在了.

速聊1:
好的,但是如何使用此连接设置DataGridView是可行的?
速聊2:
在此处为您提供完整的教程是不切实际的.您需要查看一些代码示例,也许还要看在线视频,以了解要做什么.

When I import Dataset to application in connnection string I choose "No exclude information from connection string. I will set this information in my aplication".

Now when I compile the form there is nothing to see in the DataGrid, where I must place connection in my application to connet ?

Now I have:

 public Form1()
        {
            InitializeComponent();

            using (OracleConnection con = new OracleConnection("Data Source=localhost;Persist Security Info=True;User ID=martynas;Password=xxxxxxx;Unicode=True"))
            {
                try
                {
                    con.Open();
                    OracleCommand cmd = new OracleCommand();
                    cmd.Connection = con;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

This conection is open, but DataGridView still does not show any records. I think that maybe I place connection in wrong method ?

Solutions1

You are not connecting your OracleCommand to anything. You create it but when it goes out of scope, it ceases to exists.

Talk1:
Ok, but how to set that my DataGridView using my this connection is possible?
Talk2:
It's not practical to give you a complete tutorial here. You need to look at some code samples and perhaps on-line videos to get a grasp of what to do.
转载于:https://stackoverflow.com/questions/23712662/c-sharp-oracle-connection-string-for-datagrid

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入