如何将数据添加到SQL表 [英] How to add data into sql table

查看:85
本文介绍了如何将数据添加到SQL表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我想将数据添加到sql表中.我创建了dbutilites名称类,所有的executequery executescaler等都在其中.我在那里做了一个连接字符串,并且还创建了commandobject.
现在我想知道如何在添加按钮单击事件中调用命令对象,以便可以将数据存储在sql表中.

我添加按钮的代码是:

Hello

I want to add a data into sql table. I have created dbutilites name class in which all executequery executescaler etc., are there. I have made a connection string there, and created commandobject also.
Now i want to know how to call command object in add button click event so that the data could be stored in sql table.

My code for add button is:

cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = txtName.Text.Trim(); ;
            cmd.Parameters.Add("@Description", SqlDbType.VarChar).Value = txtDesc.Text.Trim(); ;
            cmd.Parameters.Add("@Image", SqlDbType.VarChar).Value = txtImage.Text.Trim();
            cmd.Parameters.Add("@Active", SqlDbType.VarChar).Value = txtActive.Text.Trim();
            cmd.Parameters.Add("@CreatedBy", SqlDbType.VarChar).Value = txtCreatedBy.Text.Trim();
            cmd.Parameters.Add("@CreatedDate", SqlDbType.DateTime).Value = txtCreDate.Text.Trim();



            cmd.Connection = con;



请帮助我创建在dbutlites和command对象中的连接对象.
帮助



Plz help me to how to create a connection object which is in dbutlites and command object.
Help

推荐答案

如上所述,请看一下这些内容以了解如何使用ADO.NET.
C#Station ADO.NET教程 [为初学者使用ADO.NET [简单的ADO.NET数据库读取,插入,更新和删除使用C#. [ ^ ]
As said, have a look at these to learn about how to use ADO.NET.
The C# Station ADO.NET Tutorial[^]
Using ADO.NET for beginners[^]
Simple ADO.NET Database Read, Insert, Update and Delete using C#.[^]


在dbutlite中创建方法,该方法接受这些参数并在dbutlite中使用该参数.无需处理连接和命令对象.
Create method in dbutlites which accepts these parameter & use that parameter in dbutlites. No need to handle Connection & command object.


这篇关于如何将数据添加到SQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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