c#中处理关于SQL中BLOG大数据的方法

来源:互联网 发布:足球竞猜软件 编辑:程序博客网 时间:2024/06/08 06:34
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;using System.Data.Sql;using System.IO;namespace dbBlog{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void Form1_Load(object sender, EventArgs e)        {            SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder();            connBuilder.DataSource = "localhost";            connBuilder.InitialCatalog = "northwind";            connBuilder.IntegratedSecurity = true;            using (SqlConnection conn = new SqlConnection(connBuilder.ToString()))             {                try                 {                    conn.Open();                    SqlCommand command = new SqlCommand();                    command.Connection = conn;                    command.CommandText = "select firstname,lastname from employees";                    using (SqlDataReader dataReader = command.ExecuteReader())                     {                        while (dataReader.Read())                         {                            lbxImage.Items.Add(dataReader[0]+"  ");                        }                    }                }                catch(Exception ex)                {                    Console.WriteLine(ex.Message);                }            }        }        private void lbxImage_SelectedIndexChanged(object sender, EventArgs e)        {            if (lbxImage.SelectedIndex == -1)             {                return;            }            SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder();            connBuilder.DataSource = "localhost";            connBuilder.InitialCatalog = "northwind";            connBuilder.IntegratedSecurity = true;            using (SqlConnection conn = new SqlConnection(connBuilder.ToString()))            {                try                {                    conn.Open();                    SqlCommand command = new SqlCommand();                    command.Connection = conn;                    command.CommandText = "select firstName,lastName,photo from employees where firstName+' '+lastname=@name";                    string name = lbxImage.SelectedItem.ToString();                    command.Parameters.Add("@name",SqlDbType.NVarChar,100).Value=name;                    using (SqlDataReader dataReader = command.ExecuteReader(CommandBehavior.CloseConnection|CommandBehavior.SingleResult))                    {                        if (dataReader.Read())                        {                            String firstname = dataReader.GetString(0);                            System.Data.SqlTypes.SqlBytes bytes = dataReader.GetSqlBytes(2);                            try                             {                                pbxImage.Image = Image.FromStream(bytes.Stream);                            }                            //lbxImage.Items.Add(dataReader[0] + "  ");                            catch (Exception ex)                            {                                Console.WriteLine(ex.Message);                            }                        }                         }                }                catch (Exception ex)                {                    Console.WriteLine(ex.Message);                }            }            MessageBox.Show("123");        }        private void pbxImage_Click(object sender, EventArgs e)        {        }    }}

0 0
原创粉丝点击