大家好 [英] hello Every one help me

查看:68
本文介绍了大家好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SqlDataAdapter da = new SqlDataAdapter("select * from sysobjects where xtype=''u''", con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            comboBox1.DataSource = ds.Tables[0].DefaultView;
            comboBox1.DisplayMember = "name";



这行代码将所有表名赋予组合框,之后我需要一次在网格视图中显示所有表,为此,我编写了下面的代码



this lines of code gives all table names to combobox after that i need to display all tables in grid view one at a time for this i write bellow code

SqlDataAdapter da = new SqlDataAdapter("select * from "     +comboBox1.SelectedItem.ToString() + "", con);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];



但是在编译时出现诸如无效对象名称"System.Data.DataRowView"之类的错误,我该如何解决我的问题,请帮助我
我正认真面对这个问题


谢谢您



but when compiling got a error like Invalid object name ''System.Data.DataRowView'' HOW CAN I RECTIFY MY PROBLEM PLEASE HELP ME
I AM SERIOUSLY FACING THIS PROB


THANK YOU IN ADVANCE

推荐答案

尝试使用
(从* + comboBox1.SelectedValue.ToString())+",con中选择);

在组合的此绑定值属性之前..

da.Fill(ds);
comboBox1.DataSource = ds.Tables [0] .DefaultView;
comboBox1.DisplayMember =名称";
comboBox1.ValueMember =名称";
Try using
("select * from " +comboBox1.SelectedValue.ToString()) + "", con);

Before this bind value property of combo..

da.Fill(ds);
comboBox1.DataSource = ds.Tables[0].DefaultView;
comboBox1.DisplayMember = "name";
comboBox1.ValueMember = "name";


您是否正在使用comboBox1_SelectedIndexChanged事件...
如果是
您需要使用try -catch
因为第一次加载表单时,此事件会触发... ant引发异常

该代码正常工作...我已经检查过
Are you using comboBox1_SelectedIndexChanged event...
if yes
You need use try -catch
because for first time when form loaded, this event fire ...ant throw exception

This code work properly...I Have checked
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                
                SqlDataAdapter dt = new SqlDataAdapter("Select * from " + comboBox1.SelectedValue.ToString(), con.Connection);
                DataSet ds = new DataSet();
                dt.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }


您的代码和别人给您的代码都是灾难.您应该编写适当的数据层,为控件赋予有意义的名称,并通常编写可读的代码.

您不知道自己的错误是什么,这一事实证明您对C#一无所知,参加了C#课程,然后学习了ASP.NET.您还应该学习使用调试器,以便可以看到正在生成的SQL.问题是ToString返回对象的类名,而不是有人正确地说的SelectedValue.他的回答将解决您眼前的问题,但是您还有更深层次的问题需要解决.
Both your code and the code someone gave you are a disaster. You should be writing a proper data layer, giving your controls meaningful names, and generally writing readable code.

The fact that you have no idea what your error is, proves you know nothing about C#, do a C# course, then learn ASP.NET after that. You should also learn to use the debugger, so you can see the SQL being generated. The issue is that ToString returns the class name of the object, not the SelectedValue, as someone rightly said. His answer will fix your immediate problem, but you have far deeper issues that need addressing.


这篇关于大家好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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