??xml version="1.0" encoding="utf-8" standalone="yes"?>99久久亚洲一区二区三区青草,99久久精品费精品国产,九九热99久久久国产盗摄http://www.aygfsteel.com/AndyZhang/category/49333.htmlwelcome to java worldzh-cnMon, 14 May 2012 11:28:37 GMTMon, 14 May 2012 11:28:37 GMT60导出excel表(数据库里的数据表保存ؓxls的文Ӟhttp://www.aygfsteel.com/AndyZhang/archive/2012/05/14/378120.htmlSkyDreamSkyDreamMon, 14 May 2012 08:39:00 GMThttp://www.aygfsteel.com/AndyZhang/archive/2012/05/14/378120.html1.先得Z个表Table?br />2.在代码中Z个excel实例?br />   在徏实例前先引用Microsoft.Office.Interop.Excellg——d引用
   Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
   excel.Workbooks.Add(true);
3.table时的数据Q@环遍历插入到excel中?br />
具体实例如下Q?br />        string connectionstr = "Server=192.168.1.10;database=ssh;uid=sa;pwd=1234";
        string sqlstr = "select * from medstock";
        SqlConnection con = new SqlConnection(connectionstr);
        SqlCommand cmd = new SqlCommand(sqlstr,con);
        DataSet ds = new DataSet();
        DataTable db = new DataTable();
        SqlDataAdapter adp = new SqlDataAdapter(cmd);//׃SqlDataAdapter自n带有数据库打开与关闭功能,所以不用手动打开数据库与关闭?br />        adp.Fill(ds,"table1");
        db = ds.Tables["table1"];

        //建列名,Ҏ实际情况而定Q即要在excel中显C的列名Q?br />        string[] str=new string[db.Columns.Count];
        for (int i = 0; i < str.Length-2; i++)
        {
            str[i] = db.Columns[i+1].ColumnName;
        }
       //建excel实例。也是table的容器;
       Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
       excel.Workbooks.Add(true);
       //先在excel中显C出table的列名;
       for (int i = 0; i < str.Length; i++)
       {
            excel.Cells[1, i + 1] = str[i];
       }
       //再向excel中@环添加表中的每一行的每一列;
       if (db.Rows.Count > 0)
            {
                for (int i = 0; i < db.Rows.Count; i++)
                {
                    for (int j = 1; j < db.Columns.Count; j++)
                    {
                        string str1 = db.Rows[i][j].ToString();
                        excel.Cells[i + 2, j] = "'" + str1;
                   }
                }
            }
        //讄止弹出保存和覆盖的询问提示?nbsp; 
        // excel.DisplayAlerts = false;
        // excel.AlertBeforeOverwriting = false;
        excel.Save();//保存excel文g         
        excel.Quit();//保Excelq程关闭
        excel.Visible = true;// 前台可见 后台q行
        excel = null;



SkyDream 2012-05-14 16:39 发表评论
]]>
!page.ispostback 的意?用法Q?/title><link>http://www.aygfsteel.com/AndyZhang/archive/2012/05/01/377129.html</link><dc:creator>SkyDream</dc:creator><author>SkyDream</author><pubDate>Tue, 01 May 2012 14:46:00 GMT</pubDate><guid>http://www.aygfsteel.com/AndyZhang/archive/2012/05/01/377129.html</guid><description><![CDATA[<p>!Page.IsPostBackQ表C页面首ơ加?q有按钮默认是回发服务器的,所以点L钮页面会h? </p> <p>    控g都是服务器端的控? 如果你的控g设ؓ自动回发到服务器Q即AutoPostBack属性设为TrueQ,执行每次操作都会提交到后台处?是所谓的后台代码Q即以[.aspx.cs]l尾的页?,也就要在再次加蝲面的同时做出相应的操作Q所以先再次执行page_load事gQ执行了 if(!page.IsPostBack){}外的代码 后再执行其它的操作(你在面上的操作Q。处理完再回发到Q即跌{到相应的面。如果还是回发到原来的页面,则这时候该面׃是第一ơ加载了Q而是俗称的回传页?/p> <p>      ?if(!page.IsPostBack){ q里是首ơ加载页面时要实现的功能代码Q} 代码写在page_load事g中?span style="color: red">q?/span><span style="color: red">可以使用if(!IsPostBack)来判?#8212;—是否是当前页面控件的操作 Q!</span></p> <img src ="http://www.aygfsteel.com/AndyZhang/aggbug/377129.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/AndyZhang/" target="_blank">SkyDream</a> 2012-05-01 22:46 <a href="http://www.aygfsteel.com/AndyZhang/archive/2012/05/01/377129.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>winfrom与asp.net的区?/title><link>http://www.aygfsteel.com/AndyZhang/archive/2012/04/16/374730.html</link><dc:creator>SkyDream</dc:creator><author>SkyDream</author><pubDate>Mon, 16 Apr 2012 06:24:00 GMT</pubDate><guid>http://www.aygfsteel.com/AndyZhang/archive/2012/04/16/374730.html</guid><wfw:comment>http://www.aygfsteel.com/AndyZhang/comments/374730.html</wfw:comment><comments>http://www.aygfsteel.com/AndyZhang/archive/2012/04/16/374730.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/AndyZhang/comments/commentRss/374730.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/AndyZhang/services/trackbacks/374730.html</trackback:ping><description><![CDATA[<div>1. winform中可以运用缓存吗Q?br />    <span style="display: inline! important; float: none; word-spacing: 0px; font: 12px/18px Tahoma; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">所谓缓存,是把获取或生成比较麻烦的l果性的东西Q在内存中暂存。WinForm和ASP.NET的实现机制不同,不要在WinForm中用System.Web.Caching。实际上Qstring s=streamReader1.ReadToEnd()Qs变量本n已l缓存了streamReader1所对应的文件内容,q样实现~存可以了?br />     <span style="display: inline! important; float: none; word-spacing: 0px; font: 12px/18px Tahoma; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">winform的东西基本都在内存了Q你q要什么缓存啊Q?/span><br style="word-spacing: 0px; font: 12px/18px Tahoma; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px" /><span style="display: inline! important; float: none; word-spacing: 0px; font: 12px/18px Tahoma; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">cache是把~译后的|页存放在内存中Q有求时不用重新~译Q这栯U资源?span style="display: inline! important; float: none; word-spacing: 0px; font: 12px/18px Tahoma; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">如果用的是winformQ基本上不用惌个问题,因ؓ你的E序本n在内存里运行着?/span><br style="word-spacing: 0px; font: 12px/18px Tahoma; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px" /><span style="display: inline! important; float: none; word-spacing: 0px; font: 12px/18px Tahoma; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">如果是webQ缓存就是将常用的数据放到服务器的内存中Q当有不同的客户h相同的数据时Q直接从内存dQ以此提高性能?/span></span></span></div><img src ="http://www.aygfsteel.com/AndyZhang/aggbug/374730.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/AndyZhang/" target="_blank">SkyDream</a> 2012-04-16 14:24 <a href="http://www.aygfsteel.com/AndyZhang/archive/2012/04/16/374730.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Asp.net日期字符串格式化昄--DateTime.ToString()用法详解http://www.aygfsteel.com/AndyZhang/archive/2012/04/13/374039.htmlSkyDreamSkyDreamFri, 13 Apr 2012 02:39:00 GMThttp://www.aygfsteel.com/AndyZhang/archive/2012/04/13/374039.html我们l常会遇到对旉q行转换,辑ֈ不同的显C效果,默认格式?2006-6-6 14:33:34 
如果要换成成200606,06-2006,2006-6-6或更多的格式该怎么办呢Q?br />q里要用到:DateTime.ToString的方?strong>(String, IFormatProvider)
CZQ?br />using System;
using System.Globalization;
String format="D";
DateTime date=DataTime.Now;
Response.Write(date.ToString(format, DateTimeFormatInfo.InvariantInfo));
l果输出
Thursday, June 16, 2006

在这里列Z参数format格式详细用法
=======================
格式字符 兌属?说明 
d ShortDatePattern 
D LongDatePattern 
f 完整日期和时_长日期和短时_ 
F FullDateTimePatternQ长日期和长旉Q?span class="Apple-converted-space"> 
g 常规Q短日期和短旉Q?span class="Apple-converted-space"> 
G 常规Q短日期和长旉Q?span class="Apple-converted-space"> 
m、M MonthDayPattern 
r、R RFC1123Pattern 
s 使用当地旉?SortableDateTimePatternQ基?ISO 8601Q?span class="Apple-converted-space"> 
t ShortTimePattern 
T LongTimePattern 
u UniversalSortableDateTimePattern 用于昄通用旉的格?span class="Apple-converted-space"> 
U 使用通用旉的完整日期和旉Q长日期和长旉Q?span class="Apple-converted-space"> 
y、Y YearMonthPattern

下表列出了可被合q以构造自定义模式的模?br />========================================
q些模式是区分大写的;例如Q识?#8220;MM”Q但不识?#8220;mm”。如果自定义模式包含I白字符或用单引hh的字W,则输出字W串也包含这些字W。未定义为格式模式的一部分或未定义为格式字W的字符按其原义复制?/p>

格式模式 说明 Q?br />d 月中的某一天。一位数的日期没有前导零?span class="Apple-converted-space"> 
dd 月中的某一天。一位数的日期有一个前导零?span class="Apple-converted-space"> 
ddd 周中某天的羃写名Uͼ?AbbreviatedDayNames 中定义?span class="Apple-converted-space"> 
dddd 周中某天的完整名Uͼ?DayNames 中定义?span class="Apple-converted-space"> 
M 月䆾数字。一位数的月份没有前导零?span class="Apple-converted-space"> 
MM 月䆾数字。一位数的月份有一个前导零?span class="Apple-converted-space"> 
MMM 月䆾的羃写名Uͼ?AbbreviatedMonthNames 中定义?span class="Apple-converted-space"> 
MMMM 月䆾的完整名Uͼ?MonthNames 中定义?span class="Apple-converted-space"> 
y 不包含纪元的q䆾。如果不包含U元的年份小?10Q则昄不具有前导零的年份?span class="Apple-converted-space"> 
yy 不包含纪元的q䆾。如果不包含U元的年份小?10Q则昄h前导零的q䆾?span class="Apple-converted-space"> 
yyyy 包括U元的四位数的年份?span class="Apple-converted-space"> 
gg 时期或纪元。如果要讄格式的日期不h兌的时期或U元字符Ԍ则忽略该模式?span class="Apple-converted-space"> 
h 12 时制的时。一位数的小时数没有前导零?span class="Apple-converted-space"> 
hh 12 时制的时。一位数的小时数有前导零?span class="Apple-converted-space"> 
H 24 时制的时。一位数的小时数没有前导零?span class="Apple-converted-space"> 
HH 24 时制的时。一位数的小时数有前导零?span class="Apple-converted-space"> 
m 分钟。一位数的分钟数没有前导零?span class="Apple-converted-space"> 
mm 分钟。一位数的分钟数有一个前导零?span class="Apple-converted-space"> 
s U。一位数的秒数没有前导零?span class="Apple-converted-space"> 
ss U。一位数的秒数有一个前导零?span class="Apple-converted-space"> 
f U的数_ֺZ位。其余数字被截断?span class="Apple-converted-space"> 
ff U的数_ֺZ位。其余数字被截断?span class="Apple-converted-space"> 
fff U的数_ֺZ位。其余数字被截断?span class="Apple-converted-space"> 
ffff U的数_ֺ为四位。其余数字被截断?span class="Apple-converted-space"> 
fffff U的数_ֺZ位。其余数字被截断?span class="Apple-converted-space"> 
ffffff U的数_ֺ为六位。其余数字被截断?span class="Apple-converted-space"> 
fffffff U的数_ֺZ位。其余数字被截断?span class="Apple-converted-space"> 
t ?AMDesignator ?PMDesignator 中定义的 AM/PM 指示的W一个字W(如果存在Q?span class="Apple-converted-space"> 
tt ?AMDesignator ?PMDesignator 中定义的 AM/PM 指示(如果存在Q?span class="Apple-converted-space"> 
z 时区偏移量(“+”?#8220;-”后面仅跟时Q。一位数的小时数没有前导零。例如,太^z标准时间是“-8”?span class="Apple-converted-space"> 
zz 时区偏移量(“+”?#8220;-”后面仅跟时Q。一位数的小时数有前导零。例如,太^z标准时间是“-08”?span class="Apple-converted-space"> 
zzz 完整时区偏移量(“+”?#8220;-”后面跟有时和分钟)。一位数的小时数和分钟数有前导零。例如,太^z标准时间是“-08:00”?span class="Apple-converted-space"> 
: ?TimeSeparator 中定义的默认旉分隔W?span class="Apple-converted-space"> 
/ ?DateSeparator 中定义的默认日期分隔W?span class="Apple-converted-space"> 
% c 其中 c 是格式模式(如果单独使用Q。如果格式模式与原义字符或其他格式模式合qӞ则可以省?#8220;%”字符?br />/ c 其中 c 是Q意字W。照原义昄字符。若要显C反斜杠字符Q请使用“//”?/p>

只有上面W二个表中列出的格式模式才能用于创徏自定义模式;在第一个表中列出的标准格式字符不能用于创徏自定义模式。自定义模式的长度至ؓ两个字符Q例如,

DateTime.ToString( "d") q回 DateTime |“d”是标准短日期模式?span class="Apple-converted-space"> 
DateTime.ToString( "%d") q回月中的某天;“%d”是自定义模式?span class="Apple-converted-space"> 
DateTime.ToString( "d ") q回后面跟有一个空白字W的月中的某天;“d”是自定义模式?/p>

比较方便的是,上面的参数可以随意组?q且不会出错,多试?肯定会找C要的旉格式
如要得到2005q?6?q样格式的时?br />可以q样?
date.ToString("yyyyqMM?, DateTimeFormatInfo.InvariantInfo)
如此cL.

下面列出一些Asp.net中具体的日期格式化用法:
============================================
1.l定时格式化日期Ҏ: 
<ASP:BOUNDCOLUMN DATAFIELD= "JoinTime " DATAFORMATSTRING= "{0:yyyy-MM-dd} " > 
<ITEMSTYLE WIDTH= "18% " > </ITEMSTYLE > 
</ASP:BOUNDCOLUMN >

2.数据控g如DataGrid/DataList{的件格式化日期Ҏ: 
e.Item.Cell[0].Text = Convert.ToDateTime(e.Item.Cell[0].Text).ToShortDateString();

3.用Stringc{换日期显C格? 
String.Format( "yyyy-MM-dd ",yourDateTime);

4.用ConvertҎ转换日期昄格式: 
Convert.ToDateTime("2005-8-23").ToString

("yyMMdd",System.Globalization.DateTimeFormatInfo.InvariantInfo); //支持J体数据?/p>

5.直接用ToStringҎ转换日期昄格式: 
DateTime.Now.ToString("yyyyMMddhhmmss"); 
DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")

6.只显C年?span class="Apple-converted-space"> 
DataBinder.Eval(Container.DataItem,"starttime","{0:yyyy-M}")

7.昄旉所有部分,包括Q年月日时分U?span class="Apple-converted-space"> 
<asp:BoundColumn DataField="收款旉" HeaderText="收款旉" 
DataFormatString="{0:yyyy-MM-dd HH24:mm:ss}"> 
</asp:BoundColumn>



SkyDream 2012-04-13 10:39 发表评论
]]>
winform 中往数据库中d囄的两U方?/title><link>http://www.aygfsteel.com/AndyZhang/archive/2011/09/08/358267.html</link><dc:creator>SkyDream</dc:creator><author>SkyDream</author><pubDate>Thu, 08 Sep 2011 02:01:00 GMT</pubDate><guid>http://www.aygfsteel.com/AndyZhang/archive/2011/09/08/358267.html</guid><description><![CDATA[<span id="wmqeeuq" class="Apple-style-span" style="color: #999999; font-family: verdana; font-size: 12px; line-height: 18px; background-color: #10100f; "><p><span style="color: #000000; "><strong>Ҏ一Q在数据库中d囄名字Q然后把囄存在指定的文件夹?/strong></span></p><p><span style="color: #000000; ">           q种Ҏ存v来简单,但是删除的时候麻烦?/span></p><p><span style="color: #000000; ">           存:在数据库中徏一个文本字D(accessQ或者varchar字段QsqlserverQ长度能放上一张图片即?/span></p><p><span style="color: #000000; ">                 q程Q就是一般的存的insert into </span></p><p><span style="color: #000000; ">                          举个栗子Qsql数据库中有一个id字段 自增cd 一个name字段Q用于存攑֛片名U的cd是varcharcd</span></p><p><span style="color: #000000; ">                          qwinform界面中你可以拖动一个TextBoxQ用于存放\径,一个Buttonq个׃说了Q还有一个openFileDialog</span></p><p><span style="color: #000000; ">                         if (this.openFileDialog1.ShowDialog() == DialogResult.OK)</span></p><p><span style="color: #000000; ">                          {</span></p><p><span style="color: #000000; ">                               this.textBox1.Text = openFileDialog1.FileName;</span></p><p><span style="color: #000000; ">                          } //打开路径Q必不可的     q些都是是在button单击事g里完成的</span></p><p><span style="color: #000000; ">                          if (openFileDialog1.FileName.Length > 0) // 判断openFileDialog1路径的长?/span></p><p><span style="color: #000000; ">                           {</span></p><p><span style="color: #000000; ">                                  string oldName = openFileDialog1.FileName;            //定义一个stringcd的变?用于存放【文件\径?/span></p><p><span style="color: #000000; ">                                   string[] splitName = oldName.Split('.');                     //取文件的扩展名做准备?/span></p><p><span style="color: #000000; ">                                   string ext = splitName[splitName.Length - 1];          //文g的扩展名</span></p><p><span style="color: #000000; ">                                    if (ext == "jpg" || ext == "gif" || ext == "bmp" || ext == "JPG")   //限制上传囄的格?/span></p><p><span style="color: #000000; ">                                    {</span></p><p><span style="color: #000000; ">                                         string dbName = DateTime.Now.ToString("yyyyMMddhhmmss") + "." + ext; //l上传的囄起个名字Q以旉命名</span></p><p><span style="color: #000000; ">                                         string newName = AppDomain.CurrentDomain.BaseDirectory  + dbName;  //新\?q是个相对\?/span></p><p><span style="color: #000000; ">                                         File.Copy(oldName, newName, true);  //把文件从以前的\径复制到新的路径中去</span></p><p><span style="color: #000000; ">                                         //下面开始添加到数据库里面了</span></p><p><span style="color: #000000; ">                                         string constring="";//数据库的q接字符?/span></p><p><span style="color: #000000; ">                                         using (SqlConnection con=new SqlConnection (constring))</span></p><p><span style="color: #000000; ">                                          {</span></p><p><span style="color: #000000; ">                                              con.open();</span></p><p><span style="color: #000000; ">                                              stirng sql="insert into shujukuname (name) values(@name)"; //因ؓid自增的这里只需要添加图片名U?/span></p><p><span style="color: #000000; ">                                              SqlCommand cmd = new SqlCommand(sql,con);</span></p><p><span style="color: #000000; ">                                              cmd.Parameters.Add("@name",SqlDbType.VarChar).Value=TextBox1.Text.Trim();</span></p><p><span style="color: #000000; ">                                              cmd.ExecuteNonQuery();</span></p><p><span style="color: #000000; ">                                              con.Close();</span></p><p><span style="color: #000000; ">                                          }</span></p><p><span style="color: #000000; ">                                    }                     </span></p><p><span style="color: #000000; ">                           }                                                                                              //q样添加完成了</span></p><p><span style="color: #000000; ">            昄囄Q? q里一定要有一个PictureBox1</span></p><p><span style="color: #000000; ">                          要从数据库中取出q个name</span></p><p><span style="color: #000000; ">                         using (SqlConnection con=new SqlConnection (constring))</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                         {</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                              string sql="select name from shujukuname where id=' 1'   ";//当id=1的时候查询的囄的名U?/span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                               SqlDataAdapter da = new SqlDataAdapter(sql, con);</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                               con.Open();</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                               DataTable dt=new  DataTable();</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                               da.Fill(dt);</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                               string name =dt.Rows[0]["name"].ToString();</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                               con.Close();                          //q样p取出name来了Q然后进行显C?/span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                         }</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                               string path=Application.StartupPath + "http://"+ name;  //一张图片的路径</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                               if(File.Exists(path)) //Ҏq个路劲昄有没有这张图?/span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                               {</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                                      PictureBox1.Image=Image.FromFile(path);                  //PictureBox1昄的path路径的图?/span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                               }</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                              else</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                                {</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                                        PictureBox1.Image=Image.FromFile(Application.StartupPath + "http://" +默认囄);  //PictureBox1昄的默认的的图?/span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">                                }</span></p></span><span id="wmqeeuq" class="Apple-style-span" style="color: #999999; font-family: verdana; font-size: 12px; line-height: 18px; background-color: #10100f; "><p><span style="color: #000000; "><strong>winform 中往数据库中d囄的两U方式之二:直接把图片添加在sqlserver?/strong></span></p><p><span style="color: #000000; ">首先要有一个image或者binarycd的字D?/span></p><p><span style="color: #000000; ">q种是以二进制Ş式插入到数据库中</span></p><p><span id="wmqeeuq" class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #00ff00; "><span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">                 FileStream fs = new FileStream(pathName, System.IO.FileMode.Open, System.IO.FileAccess.Read);<br style="word-wrap: break-word; line-height: normal; " /></span><span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">                 byte[] buffByte = new byte[fs.Length];<br style="word-wrap: break-word; line-height: normal; " /></span><span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">                 fs.Read(buffByte, 0, (int)fs.Length);<br style="word-wrap: break-word; line-height: normal; " /></span><span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">                 fs.Close();                                        //</span><span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">数据库字DؓimagecdQ将囄转化为byte[]Q保存到数据?/span><br />      <br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">                 SqlConnection   db   =   new   SqlConnection(strConn); <br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">                 db.Open(); <br /><br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">                 string   strSQL   =   "INSERT   INTO   shujuktable (name)   values   (@name) "; <br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">                 SqlCommand   cmd   =   new   SqlCommand(strSQL,   db); <br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">                 cmd.Parameters.Add( "@name",   SqlDbType.Image); <br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">                 cmd.Parameters[ "@name"].Value   =   <span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">buffByte</span></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">; <br /><br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">                 cmd.ExecuteNonQuery();                                       //保存囄的过E?/span></p><p><span id="wmqeeuq" class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">清理资源</span></p><p><span face="Tahoma, Helvetica, Arial, serif" style="font-family: Tahoma, Helvetica, Arial, serif; color: #00ff00; "><span id="wmqeeuq" class="Apple-style-span" style="line-height: 20px; color: #000000; ">以上q部分是如何d囄Q下面这部分是读取图?/span></span></p><p><span face="Tahoma, Helvetica, Arial, serif" style="font-family: Tahoma, Helvetica, Arial, serif; color: #00ff00; "><span id="wmqeeuq" class="Apple-style-span" style="line-height: 20px; color: #000000; ">-————————————————————————————————————————————————</span></span></p><p><span style="color: #00ff00; "><span id="wmqeeuq" class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; "><span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">             SqlConnection conn = new SqlConnection(</span></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; line-height: 20px; color: #000000; ">strConn</span><span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; line-height: 21px; color: #000000; ">);</span></span></p><p><span id="wmqeeuq" class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #00ff00; "><span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; " /></span><span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">             DataTable dt = new DataTable();<br style="word-wrap: break-word; line-height: normal; " /></span><span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">             SqlDataAdapter adp = new SqlDataAdapter("select name from shujuktable where ID='1'", conn);<br style="word-wrap: break-word; line-height: normal; " /></span><span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">             adp.Fill(dt);<br style="word-wrap: break-word; line-height: normal; " /></span><span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">             byte[] buffByte = (byte[])dt.Rows[0][“name”];<br style="word-wrap: break-word; line-height: normal; " /><br style="word-wrap: break-word; line-height: normal; " /></span><span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">             MemoryStream ms = new MemoryStream(buffByte);<br style="word-wrap: break-word; line-height: normal; " /></span><span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">             Image image = Image.FromStream(ms, true);<br style="word-wrap: break-word; line-height: normal; " /><br style="word-wrap: break-word; line-height: normal; " /></span><span id="wmqeeuq" class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">             this.pictureEdit1.Image = image;</span></span></p></span><img src ="http://www.aygfsteel.com/AndyZhang/aggbug/358267.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/AndyZhang/" target="_blank">SkyDream</a> 2011-09-08 10:01 <a href="http://www.aygfsteel.com/AndyZhang/archive/2011/09/08/358267.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用q接字符?/title><link>http://www.aygfsteel.com/AndyZhang/archive/2011/09/08/358265.html</link><dc:creator>SkyDream</dc:creator><author>SkyDream</author><pubDate>Thu, 08 Sep 2011 01:46:00 GMT</pubDate><guid>http://www.aygfsteel.com/AndyZhang/archive/2011/09/08/358265.html</guid><description><![CDATA[     摘要: 有关 .NET 数据提供E序的连接字W串关键字的更多信息Q请参见ConnectionStringq接字符串关键字q接字符串的格式是用分号分隔的?值参数对列表Qkeyword1=value; keyword2=value 忽略I格Q关键字不区分大写Q尽值可能会区分大小写,q取决于数据源的大小写。要加入包含分号、单引号或双引号的|值必d双引受?nbsp;有关 .NET 数据提供E序的连...  <a href='http://www.aygfsteel.com/AndyZhang/archive/2011/09/08/358265.html'>阅读全文</a><img src ="http://www.aygfsteel.com/AndyZhang/aggbug/358265.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/AndyZhang/" target="_blank">SkyDream</a> 2011-09-08 09:46 <a href="http://www.aygfsteel.com/AndyZhang/archive/2011/09/08/358265.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C#中的@W号http://www.aygfsteel.com/AndyZhang/archive/2011/08/27/357398.htmlSkyDreamSkyDreamSat, 27 Aug 2011 04:23:00 GMThttp://www.aygfsteel.com/AndyZhang/archive/2011/08/27/357398.html 
C#中的@W号其实有很多的用法Q我们来看看@有什么神奇之处?/font> 
1.限定字符?/font>
?@ W号加在字符串前面表C其中的转义字符“?#8221;被处理?/font>
如果我们写一个文件的路径Q例?D:\文本文g"路径下的text.txt文gQ不加@W号的话写法如下Q?/font>
string fileName = "D:\\文本文g\\text.txt";
 如果使用@W号׃比较单:
string fileName = @"D:\文本文g\text.txt";

 2.让字W串跨行
有时候一个字W串写在一行中会很?比如SQL语句)Q不使用@W号Q一U写法是q样的:
string strSQL = "SELECT * FROM HumanResources.Employee AS e"
    
+ " INNER JOIN Person.Contact AS c"
    
+ " ON e.ContactID = c.ContactID"
    
+ " ORDER BY c.LastName";
 加上@W号后就可以直接换行了:
string strSQL = @"SELECT * FROM HumanResources.Employee AS e
    INNER JOIN Person.Contact AS c
    ON e.ContactID = c.ContactID
    ORDER BY c.LastName
";
 
3.在标识符中的用法
C#是不允许关键字作为标识符(cd、变量名、方法名、表I间名等)使用的,但如果加上@之后可以了Q例如: 
namespace @namespace
{
    
class
 @class
    
{
        
public static void @static(int
 @int)
        
{
            
if (@int > 0
)
            
{
                System.Console.WriteLine(
"Positive Integer"
);
            }

            
else if (@int == 0)
            
{
                System.Console.WriteLine(
"Zero"
);
            }

            
else
            
{
                System.Console.WriteLine(
"Negative Integer"
);
            }

        }

    }

}


SkyDream 2011-08-27 12:23 发表评论
]]>
վ֩ģ壺 ˮ| ֣| | Ĭ| տ| ԭ| | | | | ͷ| »| ԣ| ˮ| ɯ| | ̨| | Ϫ| | ƺ| | | ӱʡ| ӱ| ̨| | | | ɽ| | ֶ| | ݰ| ¸| ߶| | Ǩ| ˱| | ³ƶ|