C # Operations classes for WebForm and WinForm connections to SQL Server 2000 databases in. Net
Source: Internet
Author: User
server|web| Data | Database one. This is for C # connection WinForm
Note points: (1) The namespace of this class must be referenced when called
(2) The namespaces referenced in the class
Using System;
Using System.Data;
Using System.Data.SqlClient;
(3) Call Example:
DataSet DS =new DataSet ();
String Sql= "select * from [user]";
Ds=dodatabase.getdataset (SQL);
Datagrid1.datasource=ds. Tables[0]. DefaultView;
The above four behavior is bound to DATAGRID1 using the user table in the 02wangluo database to populate the dataset
This is the call to the GetDataSet method--> This method is mainly faced with the check (select)
String sql= "INSERT into Test (test_xingming) VALUES (" +txtuserid.text+ ")";
Dodatabase.executesql (SQL);
The above two lines are called the Dodatabase database operation class in the ExecuteSQL method to execute the database, delete, change operations, generally written to the Button_Click
(3) Specific operation type Code:
public class Dodatabase
{
Public Dodatabase ()
{
//
TODO: Add constructor logic here
//
}
public static DataSet GetDataSet (String sql)
{
SqlConnection conn=new SqlConnection ();
DataSet ds=new DataSet ();
Try
{
Two asp.net operations class for C # Operations SQL SERVER 2000 database
(1) Namespace in class:
Using System;
Using System.Data;
Using System.Data.SqlClient;
Using System.Collections;
Using System.Configuration;
(2) in Web.config <configuration> the following line joins the database connection string
<appSettings>
<add key= "sqlconn" value= "Data source= (local); Initial Catalog=02wangluo;user Id=sa; Password= "/>
</appSettings>
(2) Operation Class Code:
public class Dodatabase
{
public static SqlConnection sqlconn = new SqlConnection ();
Public Dodatabase ()
{
}
public static DataSet GetDataSet (String sql)
{
DataSet ds = new DataSet ();
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.