C#Gridview基本操作示例 [英] C# Gridview Basic Operations Example

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

问题描述

大家好.

我在网上搜索,但找不到包含基本数据库操作(插入,更新,删除..)的好示例.

有没有人有一个不错的链接或示例来说明如何使用SqlServer进行此类操作?

最好的问候...

Hey everyone.

I searched on the net, but couldn''t find a nice example including basic database operations(insert, update, delete..)

Does anyone has a nice link or an example to show how to make such operations using SqlServer?

My best regards...

推荐答案

添加,编辑,然后使用分页在DataGridView中删除 [ ^ ]

编辑
----------------
使用DataGridView插入,更新和删除C#中的控件(Windows应用程序) [
Add, Edit, and Delete in DataGridView with Paging[^]

EDIT
----------------
Insert, Update, Delete with DataGridView Control in C# (Windows Application)[^]


这是在表中插入值的方法.在这里,我将按钮事件上的值插入注册表中.
This is how to insert the the value in the table. Here I''m inserting the values in the registration table on the button event.
private void Register_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=.\\sqlexpress; initial catalog=yourDatabasename; integrated security=true");
try
                {
                    con.Open();                    
                   
                    SqlCommand  cmd = new SqlCommand("insert into Registration values(''" + textBox1.Text + "'',''" + textBox2.Text + "'',''" + comboBox1.Text + "'',''" + textBox4.Text + "'')", con);
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Congratulation! Successfully Register!"); 
                                        
                    con.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error Got:" + ex.Message);
                }
}



在这里,您可以如何更新记录



Here how you can update the record

private void Chpawrd_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=.\\sqlexpress; initial catalog=yourDatabasename; integrated security=true");
try
               {
                   con.Open();
                   SqlCommand cmd = new SqlCommand("update registration set password='" + textBox3.Text + "' where username='" + textBox1.Text + "'", con);
                   cmd.ExecuteNonQuery();
                   MessageBox.Show("Password changed Successfully");
               }
               catch (Exception ex)
               {
                   MessageBox.Show("Error:-" + ex.Message);
               }
               con.Close();


在这里,我正在更新现有的密码.用户名来自texbox1的位置,与此用户名相关的密码将被更改.

并且delete选项可以与where条件的update相同使用.我认为这会对您有所帮助.


Here I''m updating the existed password. Where the username is from the texbox1 and the related password from this username will be changed.

And the delete option you can use as same the update with the where condition. I think this will help you.


使用Gridview插入,更新和删除. ...简单方法 [^ ]


这篇关于C#Gridview基本操作示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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