文本框控件的数据绑定属性 [英] databinding propoerty of textbox control

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

问题描述

我正在使用文本框控件的数据绑定属性.
它仅显示该列中的一个名称.这种财产是用于这种工作的吗?
你能解释一下C#中文本框的数据绑定属性吗,我已经搜索了但没有找到答案.任何人都可以帮助我探索数据绑定属性吗?

i am using databinding property of textbox control.
it is showing only one name from the column. does this propoerty is used for such work?
can you explain databinding property of textbox in C#, i have searched but no answer was found. can anyone helpme out to explore the databinding property

推荐答案

一个文本框仅显示一个值-因此它只能显示一个值,该值来自您的单个列数据源.

如果要显示多行,多列或两者,则需要使用多行控件,例如DataGridView
A text box only shows one value - so all it can ever show is a single value from a single column of your data source.

If you want to show multiple rows, or multiple columns, or both, then you need to use a multiple row control, such as a DataGridView


Hi
无法在一个文本框行中表示整个数据库列.我始终喜欢无绑定数据库连接,因为它提供了更大的灵活性并减少了服务器计算机上的负载.不过,如果您坚持使用绑定控件,那么我建议您选择BindingNavigator或DataGridView.探索使用BindingNavigator的可能性,如果您不熟悉数据库处理,这将非常有趣.

绑定控件为您提供了直接连接到数据库的用户界面中的控件.因此,每当您对控件的值进行任何更改(例如,更改DataGridView控件中的人的姓名)时,所做的更改都会反映在主数据库本身中.要进行这些更改,您无需编写任何额外的代码.而未绑定的控件仅在需要时才建立与数据库的连接.因此,前端所做的任何更改都不会反映在数据库中.您需要为此写下单独的代码.不受约束的控制的功能是您不会一直连接到数据库,从而减轻了服务器的压力.此外,您可以每次以任何方式与数据库进行交互.

尽管绑定控件更容易创建,创建起来也更快,但未绑定控件的使用效果更好.


Ritwesh.
Hi
It is not possible to represent your entire database column in one text box line. I always prefer unbound database connectivity as it provides greater flexibility and reduce load on the server computer. Still, if you insist upon using the bound control then I would suggest you to go for BindingNavigator or DataGridView. Explore the possibilities of using BindingNavigator it is quite interesting if you are new to database handling.

Bound controls provide you a control in the user interface which is directly connected to your database. As a result of this whenever you make any change to value of the controls(say, you change the Name of a person in a DataGridView control) the change is reflected in the main database itself. To make these changes happen you need not write any extra code. While unbound controls establishes connection to the database only when needed. So any change made at the front end does not reflect in the database. You need to write down separate code for that. The facility of unbound control is that your are not constantly connected to your database which reduces the pressure on the server. Further you can interact with the database any way you want every time.

Though bound controls are easier and quicker to create, unbound controls serve better.


Ritwesh.


尝试以下代码以绑定到数据库并将其插入到数据库中:

try this code for binding to database and insert into it:

SqlConnection conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["Your ConnectionString name"].ConnectionString;
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            conn.Open();
            try
            {
                cmd.CommandText = "Insert into [Database Name] values([your Field Name that you want to insert from Textbox])";
                cmd.Parameters.Add("@Your FieldName", SqlDbType.VarChar).Value = textbox1.Text;
                cmd.ExecuteNonQuery();
            }
            catch (SqlException se)
            {
               Page.Title = "Exception :" + ex.Message;
            }
            finally
            {
                    conn.Close();
            }


这篇关于文本框控件的数据绑定属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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