none
求救啊,问一个关于ADO类型的问题求大神 RRS feed

  • 问题

  • 小弟做一个winform程序,需要吧一个text文件传入数据库,然后在从数据库取出来,显示到textbox上面,求教为何我取不出来。取varchar(max)类型的时候是int32类型啊

     using (StreamReader sw = new StreamReader(filetext2.Text, Encoding.GetEncoding("GB2312")))
                {
                    while (sw.ReadLine() != null)
                    {

                        string sql = "insert into newinfo(contents,author) values(@by,@author)";
                        string zuozhe = Txtauto.Text.Trim();
                        SqlParameter[] pms = new SqlParameter[]{
                            new SqlParameter("@by", sw.ReadToEnd())
                        ,new SqlParameter("@author",zuozhe)};
                        SqlHelper.ExcuteNonquery(sql, CommandType.Text, pms);
                        MessageBox.Show("插入成功");
                    }
                }

    2014年3月24日 12:41

答案

  • 您好,

    請參考,

    先讀取到line變數再判斷是否為null

    using (StreamReader sw = new StreamReader(filetext2.Text, Encoding.GetEncoding("GB2312")))
    {
    	string line;
    	while ((line = sw.ReadLine()) != null)
    	{
    
    		string sql = "insert into newinfo(contents,author) values(@by,@author)";
    		string zuozhe = Txtauto.Text.Trim();
    		SqlParameter[] pms = new SqlParameter[]{
    			new SqlParameter("@by", line)
    		,new SqlParameter("@author",zuozhe)};
    		SqlHelper.ExcuteNonquery(sql, CommandType.Text, pms);
    		MessageBox.Show("插入成功");
    	}
    }


    亂馬客blog: http://www.dotblogs.com.tw/rainmaker/

    2014年3月25日 2:06

全部回复

  • 您好,

    請參考,

    先讀取到line變數再判斷是否為null

    using (StreamReader sw = new StreamReader(filetext2.Text, Encoding.GetEncoding("GB2312")))
    {
    	string line;
    	while ((line = sw.ReadLine()) != null)
    	{
    
    		string sql = "insert into newinfo(contents,author) values(@by,@author)";
    		string zuozhe = Txtauto.Text.Trim();
    		SqlParameter[] pms = new SqlParameter[]{
    			new SqlParameter("@by", line)
    		,new SqlParameter("@author",zuozhe)};
    		SqlHelper.ExcuteNonquery(sql, CommandType.Text, pms);
    		MessageBox.Show("插入成功");
    	}
    }


    亂馬客blog: http://www.dotblogs.com.tw/rainmaker/

    2014年3月25日 2:06
  • 你好楼主,

    >>求教为何我取不出来

    楼主你是怎么取得数据,可以展示下你的代码和你存的text内容吗?


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年3月25日 3:40
    版主