将组合框值传递给类文件集失败 [英] Passing combobox value to classfile set failed

查看:51
本文介绍了将组合框值传递给类文件集失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Object reference not set to an instance of an object










Form2 fr2 = new Form2();
                    
                     string srv = fr2.sqlServerComboBox.SelectedItem.ToString();
                     string pass = fr2.passwordTextBox.Text.ToString();
                     string database = fr2.databaseComboBox.SelectedItem.ToString();
                   

                   string str = @"Data Source=srv;" + "Initial Catalog=database;" + "Persist Security Info=True;" + "User ID=sa;" + "Password=pass";

推荐答案

您没有显示表单,除非您在Form2中有自动选择的代码组合框上的东西什么都不会被选中。此外,如果您没有将这些控件公开,那么您将无法访问它们。

查看OriginalGriff的文章在两种形式之间传递信息,第2部分:儿童到父母 [ ^ ]
You're not showing the form so unless you have code in Form2 that automatically selects something on the combobox nothing is going to be selected. Also if you haven't made those controls public then you're not going to be able to access them.
Have a look at OriginalGriff's article Transferring information between two forms, Part 2: Child to Parent[^]


您正在请求null的属性(即ab,其中a为null)。我们无法运行您的知识输入代码,因此我们无法真正帮助您。简单地创建Form2的实例可能不会在您的下拉列表中选择项目,所以也许SelectedItem为空?你需要使用调试器找出什么是null。



c# - 什么是NullReferenceException以及如何解决它? - 堆栈溢出 [ ^ ]



掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]
You are requesting the property of something that is null (ie a.b where "a" is null). We can't run your code of know your inputs so it's impossible for us to help really. It's likely that simply creating an instance of Form2 is not selecting items in your dropdowns so maybe SelectedItem is null? You'll need to use the debugger to find out what is null.

c# - What is a NullReferenceException and how do I fix it? - Stack Overflow[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]


这篇关于将组合框值传递给类文件集失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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