using System.Data;
using System.Data.Common;
using System.Configuration;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// SqlConnection conn = new SqlConnection("uid=sa;pwd=11;data source=.;database=gwdb");
// SqlDataAdapter sda = new SqlDataAdapter("select * from users where uname=@uname and upwd=@upwd",conn);
// sda.SelectCommand.Parameters.Add("@uname", SqlDbType.VarChar, 50, "uname");
// //sda.SelectCommand.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
// sda.SelectCommand.Parameters.Add("@upwd", "test");
// sda.SelectCommand.Parameters["@uname"].Value = "test";
//// sda.SelectCommand.Parameters["@upwd"].Value = "test";
// DataSet ds = new DataSet();
// sda.Fill(ds);
// Response.Write(ds.Tables[0].Rows.Count);
}
protected void Button2_Click(object sender, EventArgs e)
{
DBHelper.ExecuteCommand("insert into users(uname,upwd) values('dd','dd')");
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlParameter[] sql = new SqlParameter[2];
sql[0] = new SqlParameter("@uname", SqlDbType.VarChar, 50, "uname");
sql[1] = new SqlParameter("@upwd", SqlDbType.VarChar, 20, "upwd");
sql[0].Value = "qq";
sql[1].Value = "qq";
DBHelper.ExecuteCommand("insert into users(uname,upwd) values(@uname,@upwd)",sql);
}
protected void Button4_Click(object sender, EventArgs e)
{
SqlDataAdapter sda = new SqlDataAdapter();
SqlConnection conn = new SqlConnection("uid=sa;pwd=11;data source=.;database=gwdb");
SqlCommand select = new SqlCommand("select * from users", conn);
sda.SelectCommand = select;
SqlCommand insert=new SqlCommand("insert into users(uname,upwd) values(@uname,@upwd)",conn);
insert.Parameters.Add("@uname", SqlDbType.VarChar, 50, "uname");
insert.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
insert.Parameters["@uname"].Value = "dog";
insert.Parameters["@upwd"].Value= "dog";
sda.InsertCommand = insert;
SqlCommand update = new SqlCommand("update users set upwd=@upwd",conn);
update.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
sda.UpdateCommand = update;
SqlCommand delete = new SqlCommand("delete from users where uid=@id",conn);
delete.Parameters.Add("@id", SqlDbType.Int, 4, "uid");
sda.DeleteCommand = delete;
DataTable dt = new DataTable();
DataTableMapping dtm = new DataTableMapping("users", "dt");
sda.Fill(dt);
sda.Update(dt);
Response.Write(dt.Rows.Count);
}
}
插入后没有数据。不知道为什么。查看可以。
7 个解决方案
#1
打开事件查看器,自己看看数据库在执行什么sql语句
#2
查看可以 说明数据库连接没问题 插入不行 那就是插入的语句有问题呗或者是插入的值不符合要求
#3
有没有报错啊?你看看数据库有没有插入数据啊?刷新一下试试!
#4
using System;
using System.Data;
using System.Data.Common;
using System.Configuration;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// SqlConnection conn = new SqlConnection("uid=sa;pwd=11;data source=.;database=gwdb");
// SqlDataAdapter sda = new SqlDataAdapter("select * from users where uname=@uname and upwd=@upwd",conn);
// sda.SelectCommand.Parameters.Add("@uname", SqlDbType.VarChar, 50, "uname");
// //sda.SelectCommand.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
// sda.SelectCommand.Parameters.Add("@upwd", "test");
// sda.SelectCommand.Parameters["@uname"].Value = "test";
//// sda.SelectCommand.Parameters["@upwd"].Value = "test";
// DataSet ds = new DataSet();
// sda.Fill(ds);
// Response.Write(ds.Tables[0].Rows.Count);
}
protected void Button2_Click(object sender, EventArgs e)
{
DBHelper.ExecuteCommand("insert into users(uname,upwd) values('dd','dd')");
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlParameter[] sql = new SqlParameter[2];
sql[0] = new SqlParameter("@uname", SqlDbType.VarChar, 50, "uname");
sql[1] = new SqlParameter("@upwd", SqlDbType.VarChar, 20, "upwd");
sql[0].Value = "qq";
sql[1].Value = "qq";
DBHelper.ExecuteCommand("insert into users(uname,upwd) values(@uname,@upwd)",sql);
}
protected void Button4_Click(object sender, EventArgs e)
{
SqlDataAdapter sda = new SqlDataAdapter();
SqlConnection conn = new SqlConnection("uid=sa;pwd=11;data source=.;database=gwdb");
SqlCommand select = new SqlCommand("select * from users", conn);
sda.SelectCommand = select;
SqlCommand insert=new SqlCommand("insert into users(uname,upwd) values(@uname,@upwd)",conn);
insert.Parameters.Add("@uname", SqlDbType.VarChar, 50, "uname");
insert.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
insert.Parameters["@uname"].Value = "dog";
insert.Parameters["@upwd"].Value= "dog";
sda.InsertCommand = insert;
SqlCommand update = new SqlCommand("update users set upwd=@upwd",conn);
update.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
sda.UpdateCommand = update;
SqlCommand delete = new SqlCommand("delete from users where uid=@id",conn);
delete.Parameters.Add("@id", SqlDbType.Int, 4, "uid");
sda.DeleteCommand = delete;
DataTable dt = new DataTable();
DataTableMapping dtm = new DataTableMapping("users", "dt");
sda.Fill(dt);
sda.Update(dt);
Response.Write(dt.Rows.Count);
}
}
插入后没有数据。不知道为什么。查看可以。插入语句没有问题。就是插入没有数据,修改也不能。
using System.Data;
using System.Data.Common;
using System.Configuration;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// SqlConnection conn = new SqlConnection("uid=sa;pwd=11;data source=.;database=gwdb");
// SqlDataAdapter sda = new SqlDataAdapter("select * from users where uname=@uname and upwd=@upwd",conn);
// sda.SelectCommand.Parameters.Add("@uname", SqlDbType.VarChar, 50, "uname");
// //sda.SelectCommand.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
// sda.SelectCommand.Parameters.Add("@upwd", "test");
// sda.SelectCommand.Parameters["@uname"].Value = "test";
//// sda.SelectCommand.Parameters["@upwd"].Value = "test";
// DataSet ds = new DataSet();
// sda.Fill(ds);
// Response.Write(ds.Tables[0].Rows.Count);
}
protected void Button2_Click(object sender, EventArgs e)
{
DBHelper.ExecuteCommand("insert into users(uname,upwd) values('dd','dd')");
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlParameter[] sql = new SqlParameter[2];
sql[0] = new SqlParameter("@uname", SqlDbType.VarChar, 50, "uname");
sql[1] = new SqlParameter("@upwd", SqlDbType.VarChar, 20, "upwd");
sql[0].Value = "qq";
sql[1].Value = "qq";
DBHelper.ExecuteCommand("insert into users(uname,upwd) values(@uname,@upwd)",sql);
}
protected void Button4_Click(object sender, EventArgs e)
{
SqlDataAdapter sda = new SqlDataAdapter();
SqlConnection conn = new SqlConnection("uid=sa;pwd=11;data source=.;database=gwdb");
SqlCommand select = new SqlCommand("select * from users", conn);
sda.SelectCommand = select;
SqlCommand insert=new SqlCommand("insert into users(uname,upwd) values(@uname,@upwd)",conn);
insert.Parameters.Add("@uname", SqlDbType.VarChar, 50, "uname");
insert.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
insert.Parameters["@uname"].Value = "dog";
insert.Parameters["@upwd"].Value= "dog";
sda.InsertCommand = insert;
SqlCommand update = new SqlCommand("update users set upwd=@upwd",conn);
update.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
sda.UpdateCommand = update;
SqlCommand delete = new SqlCommand("delete from users where uid=@id",conn);
delete.Parameters.Add("@id", SqlDbType.Int, 4, "uid");
sda.DeleteCommand = delete;
DataTable dt = new DataTable();
DataTableMapping dtm = new DataTableMapping("users", "dt");
sda.Fill(dt);
sda.Update(dt);
Response.Write(dt.Rows.Count);
}
}
插入后没有数据。不知道为什么。查看可以。插入语句没有问题。就是插入没有数据,修改也不能。
#5
DataTable dt = new DataTable();
DataTableMapping dtm = new DataTableMapping("users", "dt");
sda.Fill(dt);
sda.Update(dt);
datatable发生变化了?
DataTableMapping dtm = new DataTableMapping("users", "dt");
sda.Fill(dt);
sda.Update(dt);
datatable发生变化了?
#6
没有变化啊。就是插入数据不行。
#7
我搞定的了。谢谢大家
#1
打开事件查看器,自己看看数据库在执行什么sql语句
#2
查看可以 说明数据库连接没问题 插入不行 那就是插入的语句有问题呗或者是插入的值不符合要求
#3
有没有报错啊?你看看数据库有没有插入数据啊?刷新一下试试!
#4
using System;
using System.Data;
using System.Data.Common;
using System.Configuration;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// SqlConnection conn = new SqlConnection("uid=sa;pwd=11;data source=.;database=gwdb");
// SqlDataAdapter sda = new SqlDataAdapter("select * from users where uname=@uname and upwd=@upwd",conn);
// sda.SelectCommand.Parameters.Add("@uname", SqlDbType.VarChar, 50, "uname");
// //sda.SelectCommand.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
// sda.SelectCommand.Parameters.Add("@upwd", "test");
// sda.SelectCommand.Parameters["@uname"].Value = "test";
//// sda.SelectCommand.Parameters["@upwd"].Value = "test";
// DataSet ds = new DataSet();
// sda.Fill(ds);
// Response.Write(ds.Tables[0].Rows.Count);
}
protected void Button2_Click(object sender, EventArgs e)
{
DBHelper.ExecuteCommand("insert into users(uname,upwd) values('dd','dd')");
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlParameter[] sql = new SqlParameter[2];
sql[0] = new SqlParameter("@uname", SqlDbType.VarChar, 50, "uname");
sql[1] = new SqlParameter("@upwd", SqlDbType.VarChar, 20, "upwd");
sql[0].Value = "qq";
sql[1].Value = "qq";
DBHelper.ExecuteCommand("insert into users(uname,upwd) values(@uname,@upwd)",sql);
}
protected void Button4_Click(object sender, EventArgs e)
{
SqlDataAdapter sda = new SqlDataAdapter();
SqlConnection conn = new SqlConnection("uid=sa;pwd=11;data source=.;database=gwdb");
SqlCommand select = new SqlCommand("select * from users", conn);
sda.SelectCommand = select;
SqlCommand insert=new SqlCommand("insert into users(uname,upwd) values(@uname,@upwd)",conn);
insert.Parameters.Add("@uname", SqlDbType.VarChar, 50, "uname");
insert.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
insert.Parameters["@uname"].Value = "dog";
insert.Parameters["@upwd"].Value= "dog";
sda.InsertCommand = insert;
SqlCommand update = new SqlCommand("update users set upwd=@upwd",conn);
update.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
sda.UpdateCommand = update;
SqlCommand delete = new SqlCommand("delete from users where uid=@id",conn);
delete.Parameters.Add("@id", SqlDbType.Int, 4, "uid");
sda.DeleteCommand = delete;
DataTable dt = new DataTable();
DataTableMapping dtm = new DataTableMapping("users", "dt");
sda.Fill(dt);
sda.Update(dt);
Response.Write(dt.Rows.Count);
}
}
插入后没有数据。不知道为什么。查看可以。插入语句没有问题。就是插入没有数据,修改也不能。
using System.Data;
using System.Data.Common;
using System.Configuration;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// SqlConnection conn = new SqlConnection("uid=sa;pwd=11;data source=.;database=gwdb");
// SqlDataAdapter sda = new SqlDataAdapter("select * from users where uname=@uname and upwd=@upwd",conn);
// sda.SelectCommand.Parameters.Add("@uname", SqlDbType.VarChar, 50, "uname");
// //sda.SelectCommand.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
// sda.SelectCommand.Parameters.Add("@upwd", "test");
// sda.SelectCommand.Parameters["@uname"].Value = "test";
//// sda.SelectCommand.Parameters["@upwd"].Value = "test";
// DataSet ds = new DataSet();
// sda.Fill(ds);
// Response.Write(ds.Tables[0].Rows.Count);
}
protected void Button2_Click(object sender, EventArgs e)
{
DBHelper.ExecuteCommand("insert into users(uname,upwd) values('dd','dd')");
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlParameter[] sql = new SqlParameter[2];
sql[0] = new SqlParameter("@uname", SqlDbType.VarChar, 50, "uname");
sql[1] = new SqlParameter("@upwd", SqlDbType.VarChar, 20, "upwd");
sql[0].Value = "qq";
sql[1].Value = "qq";
DBHelper.ExecuteCommand("insert into users(uname,upwd) values(@uname,@upwd)",sql);
}
protected void Button4_Click(object sender, EventArgs e)
{
SqlDataAdapter sda = new SqlDataAdapter();
SqlConnection conn = new SqlConnection("uid=sa;pwd=11;data source=.;database=gwdb");
SqlCommand select = new SqlCommand("select * from users", conn);
sda.SelectCommand = select;
SqlCommand insert=new SqlCommand("insert into users(uname,upwd) values(@uname,@upwd)",conn);
insert.Parameters.Add("@uname", SqlDbType.VarChar, 50, "uname");
insert.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
insert.Parameters["@uname"].Value = "dog";
insert.Parameters["@upwd"].Value= "dog";
sda.InsertCommand = insert;
SqlCommand update = new SqlCommand("update users set upwd=@upwd",conn);
update.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
sda.UpdateCommand = update;
SqlCommand delete = new SqlCommand("delete from users where uid=@id",conn);
delete.Parameters.Add("@id", SqlDbType.Int, 4, "uid");
sda.DeleteCommand = delete;
DataTable dt = new DataTable();
DataTableMapping dtm = new DataTableMapping("users", "dt");
sda.Fill(dt);
sda.Update(dt);
Response.Write(dt.Rows.Count);
}
}
插入后没有数据。不知道为什么。查看可以。插入语句没有问题。就是插入没有数据,修改也不能。
#5
DataTable dt = new DataTable();
DataTableMapping dtm = new DataTableMapping("users", "dt");
sda.Fill(dt);
sda.Update(dt);
datatable发生变化了?
DataTableMapping dtm = new DataTableMapping("users", "dt");
sda.Fill(dt);
sda.Update(dt);
datatable发生变化了?
#6
没有变化啊。就是插入数据不行。
#7
我搞定的了。谢谢大家