今天想把FreeTextBox这个第三方控件给吃透!]
可是调试了许多次还是出错!!!!
我页面就放了一个FreeTextBox控件的一个Button按钮!!!
想实现的功能是!点提交的时候可以把FreeTextBox控件里的东西添加到数据库里!NewsId NewsTitle Newsbody UserId PubDate 上面是我数据库里的字段~~~~~下面是我的代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using FreeTextBoxControls;
using FreeTextBoxControls.Design;
using FreeTextBoxControls.Common;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection myconn = new SqlConnection("server=.;database=one;uid=sa;pwd=123");
SqlCommand cmd = new SqlCommand("select * from News where Userid=1", myconn);
myconn.Open();
SqlDataReader mydr;
mydr = cmd.ExecuteReader();
mydr.Close();
myconn.Close();
}
} protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection myconn = new SqlConnection("server=.;database=one;uid=sa;pwd=123");
SqlCommand mycmd = new SqlCommand("insert into News values('" + FreeTextBox1.Text + "')", myconn);
myconn.Open();
mycmd.ExecuteNonQuery();
myconn.Close();
}
}
可是调试了许多次还是出错!!!!
我页面就放了一个FreeTextBox控件的一个Button按钮!!!
想实现的功能是!点提交的时候可以把FreeTextBox控件里的东西添加到数据库里!NewsId NewsTitle Newsbody UserId PubDate 上面是我数据库里的字段~~~~~下面是我的代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using FreeTextBoxControls;
using FreeTextBoxControls.Design;
using FreeTextBoxControls.Common;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection myconn = new SqlConnection("server=.;database=one;uid=sa;pwd=123");
SqlCommand cmd = new SqlCommand("select * from News where Userid=1", myconn);
myconn.Open();
SqlDataReader mydr;
mydr = cmd.ExecuteReader();
mydr.Close();
myconn.Close();
}
} protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection myconn = new SqlConnection("server=.;database=one;uid=sa;pwd=123");
SqlCommand mycmd = new SqlCommand("insert into News values('" + FreeTextBox1.Text + "')", myconn);
myconn.Open();
mycmd.ExecuteNonQuery();
myconn.Close();
}
}
是不是这个意思?
能帮一下忙吗?
楼主,你会错9楼的意思了,你那是在加拼SQL语句。。
例如:
string count = FreeTextBox.Text;
SqlConnection myconn = new SqlConnection("server=.;database=one;uid=sa;pwd=123");
SqlCommand mycmd = new SqlCommand("Insert Into News Set Count=@Count",myconn)
mycmd.parenment("@Count",count);
试着用你的方法给它传个值:
FreeTextBox.Text = "adfb'and Delete * From News'";
得到的SQL语句是:Insert Into News Values "adfb" and Delete * From News
这样把你的表都给删除了````