数据库编程初,数据库程序设计

刚学到数据库编制程序,书上的文字、代码一大堆,是人没意志力,恼火!

叁个粗略的c#与数据库的连接,不过短短6行代码,作者就弄了好一阵子,疏忽!笔者把“Data
Source”写成了“DataSource”,结果连不上,后来算是开采,

style=”font-family: 宋体; line-height: normal; font-size: 12px; “> style=”color: #0000FF;”>using System;

  c#和数据库的结缘编制程序,给自家打击挺大的,让自家浑浑噩噩,不亮堂该干嘛了。

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

  首先是c#与数据库的链接,开端学的几天,写不出来。过来几天,好些个了。有些概念不通晓,不精通她们终究用来干嘛的,曾几何时用,给怎么用,只好参照他事他说加以考察老师给的代码,做领会后依然没感到到,自身可能写不出去,书上写的太肤浅了,例子又不确定,未有目的性。

namespace zsg
{
    public partial class Form1 : Form
    {
        private SqlConnection
dbConnection;
        public Form1()
        {
            InitializeComponent();
        }
        //连接数据库
        private void button1_Click(object sender, EventArgs e)
        {
            string strConn;
            try
            {
                dbConnection = new
SqlConnection();
                strConn = “Data Source=localhost;”;
                strConn += “Initial Catalog=lunwen;”;
                strConn += “Integrated Security=True”;
                dbConnection.ConnectionString = strConn;
                
                label4.Text = “连接成功”;
            }
            catch (Exception e3)
            {
                MessageBox.Show(e3.Message);
            }
        }
    }
}

using System;

 要铭记在心教诲,细工出好活。要有意志力。付出总有回报。

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

namespace dddd

{

    

    public partial class Form1 : Form

    {

        private SqlConnection dbConnection;

        private SqlDataAdapter adapter;

        private DataSet ds;

        DataGridView dataGrid;

        public Form1()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            string conn;

            conn = “Data Source=localhost;Initial
Catalog=lunwen;Integrated Security=true”;

            dbConnection = new SqlConnection();

            dbConnection.ConnectionString = conn;

            label1.Text = “连接成功”;

        }

        private void button2_Click(object sender, EventArgs e)

        {

            

            try

            {

                string sqlString;

                sqlString = “SELECT * FROM 产品;”;

                adapter = new SqlDataAdapter(sqlString, dbConnection);

发表评论

电子邮件地址不会被公开。 必填项已用*标注