betway必威-betway必威官方网站
做最好的网站

可空值类型,怎么将输入内容修改为保存到本地

核心提示:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;//所引入的命名空间

第20课-数据库开发及ado.net

怎么将输入内容修改为保存到本地 50C
现在我这代码是输入内容用Codesoft打印出来,现在想修改为将输入内容保存为.txt格式到本地或网络盘,如txtTargetQty为4则每输入4个保存为一个文件,并且名称以第一个输入内容命名
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.IO;
using System.Data.OleDb;
using System.Diagnostics;
using System.Web;
using System.Net;
using System.Collections;

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

可空值类型,资料管理器,多条件查询,Case

namespace PrintSN
{
public partial class MainForm : Form
{
private DataTable myDs = new DataTable();

//所引入的命名空间 using System.Data.Sql;

SqlHelper

 public MainForm() { InitializeComponent(); } private void txtInput_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == Keys.Enter) { string strInput = txtInput.Text; txtTargetQty.Text = Common.getConfigValueKey("PrintSNCount"); if (strInput.Equals { undo(); txtInput.SelectAll(); txtInput.Focus(); return; } else { if (dataGridView1.Rows.Count >0) { string strSN = ""; for (int i = 0; i < dataGridView1.Rows.Count; i  ) { strSN = dataGridView1.Rows[i].Cells[0].Value.ToString(); if (strInput.Equals { ShowInformation("SN 重复,请扫描其他的SN ! ", "NG"); txtInput.SelectAll(); txtInput.Focus(); return; } } } if (txtScanQty.Text.Equals((Int32.Parse(txtTargetQty.Text) - 1).ToString { int index = this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[index].Cells[0].Value = strInput; ArrayList SnDetail = new ArrayList(); for (int i = 0; i < dataGridView1.Rows.Count; i  ) { SnDetail.Add(dataGridView1.Rows[i].Cells[0].Value.ToString; } SoftCodePrint Print = new SoftCodePrint(); Print.PrintSNLabel(strInput, SnDetail); txtScanQty.Text = "0"; dataGridView1.Rows.Clear(); ShowInformation("打印完成,请扫描的下一個SN ! ", "OK"); } else { txtScanQty.Text = (Int32.Parse(txtScanQty.Text)   1).ToString(); ShowInformation("请扫描的下一個SN ! ", "OK"); int index = this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[index].Cells[0].Value = strInput; } txtInput.SelectAll(); txtInput.Focus(); return; } } } private void undo() { //txtTargetQty.Text = ""; txtScanQty.Text = "0"; dataGridView1.Rows.Clear(); ShowInformation("UNDO 操作成功,請掃描 SN! ", "OK"); } private void ShowInformation(string sInfo, string sType) { lblShowMessageInfo.Text = sInfo; if (sType.Equals { lblShowMessageInfo.BackColor = System.Drawing.Color.FromArgb(((System.Byte), ((System.Byte), ((System.Byte); } if (sType.Equals { lblShowMessageInfo.BackColor = System.Drawing.Color.FromArgb(((System.Byte), ((System.Byte), ((System.Byte); } if (sType.Equals { lblShowMessageInfo.BackColor = System.Drawing.Color.Red; } } private void MainForm_Load(object sender, EventArgs e) { txtTargetQty.Text = Common.getConfigValueKey("PrintSNCount"); } private void MainForm_Shown(object sender, EventArgs e) { txtInput.SelectAll(); txtInput.Focus(); }}

namespace EnumSqlServer { public partial class MainForm : Form { public MainForm() { InitializeComponent(); }

using System;

}

private void MainForm_Load(object sender, EventArgs e) { //枚举本地网络内所有可用SqlServer实例 SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance; //返回 //---------------------------------------------------------------------------- // ServerName|服务器的名称 //---------------------------------------------------------------------------- // InstanceName|服务器实例的名称。如果服务器作为默认实例运行,则为空白 //---------------------------------------------------------------------------- // IsClustered|指示服务器是否属于群集 //---------------------------------------------------------------------------- // Version|服务器的版本(SQLServer2000为8.00.x,SQLServer2005为9.00.x) //---------------------------------------------------------------------------- DataTable dt = instance.GetDataSources(); //绑定 cboServerList.DataSource = CreateCboDataSource(dt); }

using System.Collections.Generic;

/// summary /// 取得ComBox的数据源 /// /summary /// param name=dt/param /// returns/returns private Liststring CreateCboDataSource(DataTable dt) { Liststring list = new Liststring();

using System.Configuration;

foreach (DataRow dr in dt.Rows) { //只取ServerName list.Add(dr[0].ToString()); }

using System.Data;

return list; } } }

using System.Data.SqlClient;

using System.Text;

namespace _02省市联动

{

   public static  class SqlHelper

    {

       //常量 无法修改

       private const string A = "aaa";

       //readonly 是一个只读的变量,只能在声明或构造函数中修改

       //只读变量只能在构造函数或者是一开始声明变量的时候赋值,不允许在其它地方为变量赋值。

       //连接字符串

       private static readonly string conStr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

    

     

       /// <summary>

       /// 封装一个ExecuteNonQuery方法,执行insert、delete、updata

betway必威官方网站,       /// </summary>

       /// <param name="sql"></param>

       /// <param name="pms"></param>

       /// <returns></returns>

       public static int ExecuteQuery(string sql,params SqlParameter[] pms)

       {

           using (SqlConnection con=new SqlConnection (conStr))

           {

               using (SqlCommand com=new SqlCommand (sql,con))

               {

                   if (pms!=null)

                   {

                       com.Parameters.AddRange(pms);

                   }

                   con.Open();

                   return com.ExecuteNonQuery();

               }

           }

       }

       /// <summary>

       /// 封装返回一个单个值的方法

       /// </summary>

       /// <returns></returns>

       public static object ExecuteScalar(string sql,params SqlParameter[] pms)

       {

           using (SqlConnection con = new SqlConnection(conStr))

           {

               using (SqlCommand com=new SqlCommand (sql,con))

               {

                   if (pms!=null)

                   {

                       com.Parameters.AddRange(pms);

                   }

                   con.Open();

                   return com.ExecuteScalar();

               }

           }

       }

       /// <summary>

       /// 封装一个返回SqlDataReader的方法

       /// </summary>

       /// <returns></returns>

       public static SqlDataReader  ExecuteReader(string sql,params SqlParameter[] pms)

       {

              SqlConnection con=new SqlConnection (conStr);

               using (SqlCommand com=new SqlCommand (sql,con))

               {

                   if (pms!=null)

                   {

                       com.Parameters.AddRange(pms);

                   }

                   try

                   {

                       con.Open();

                       return com.ExecuteReader(System.Data.CommandBehavior.CloseConnection);   

                   }

                   catch (Exception)

                   {

                       con.Close();

                       con.Dispose();

                       throw;

                   }

                   

                }

       }

       public static DataTable ExecuteDataTable(string sql,params SqlParameter[] pms)

       {

           DataTable dt = new DataTable();

           using (SqlDataAdapter adapter=new SqlDataAdapter (sql,conStr ))

           {

               //如何添加参数

               adapter.Fill(dt);

           }

           return dt;

       }

    }

本文由betway必威发布于编程开发,转载请注明出处:可空值类型,怎么将输入内容修改为保存到本地

TAG标签: betway必威
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。