根据参数在userInfo表中查询等于参数的那条数据
select name from userInfo where id=" + Request.QueryString["id"].ToString() + "写入到list表中
select * from list如何写cs代码,谢谢
select name from userInfo where id=" + Request.QueryString["id"].ToString() + "写入到list表中
select * from list如何写cs代码,谢谢
解决方案 »
- config文件问题
- 已知表主键的值,如何能修改该行其它列中的数据?急!!
- 如何获取datagrid中的模版列的头部的子控件的引用?
- 事务应该写在逻辑层还是数据层?
- 如何防止程序上被人上传木马
- VS2005是不是倒退了???
- 一个单点登陆的问题?单点登陆的ticket一般放在那里的?
- 求教:通过点击GirdView控件中的超级链接HyperLinkField打开一个新的小窗口页面
- 一个关于刷新的问题 大家帮忙看看
- 新手请教,如果使用ImageButton控件只触发单击事件,而不提交到服务器,谢谢!
- 关于弹出对话框后跳转页面的问题~~~~
- Request .QueryString 传值 比较郁闷的问题?
--
千万不要这样写。
首先要判断if(!string.isnullorEmpty(Request.QueryString["id"]))
2.还要把int id=int.parse(Request.QueryString["id"].ToString())
3.最好以参数形式进去。关于怎么执行sql然后填充到一个DataTable中,你可以去看看一些开源的SqlHelper。
sql数据库的
就把userInfo表中的name写入到list这个字段的mxname里去
if(!string.isnullorEmpty(Request.QueryString["id"]))
{
int aa=int.parse(Request.QueryString["id"].ToString());
string sql = "select name from userInfo where id = aa";
}
说实话,“list这个字段的mxname”是嘛玩意儿?我真没看懂!
但是报错是什么原因呢》
行 37: insert into list(mxname) select name from userInfo where id="uid
行 38:
行 39: }
源文件: d:\cpan\Inetpub\fangan\改版2\sjorder\snet\kaichuang\p_list_d.aspx.cs 行: 37
行 36:
行 37: insert into list(mxname) select name from userInfo where id="uid
行 38:
行 39: }
源文件: d:\cpan\Inetpub\fangan\改版2\sjorder\snet\kaichuang\p_list_d.aspx.cs 行: 37
insert into list(mxname) select name from userInfo where id=" + uid
uid就是你获得的uid = Request.QueryString["id"].ToString()你不就是根据id找一个表中的信息插入到另外一个表中啊?
大家估计很忙,让我这个裤衩帮你解决吧:
private bool IsIDLegal(ref string ID)
{
if (Request.QueryString["id"] == null)
{
return false;
}
else
{
string id = Request.QueryString["id"].ToString();
string patten = "^[1-9][0-9]*$";
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(patten);
System.Text.RegularExpressions.Match m = reg.Match(id);
if (m.Success)
{
ID = id;
return true;
}
else
{
return false;
}
}
} private string Query()
{
string ID = "";
string name = "";
if (IsIDLegal(ref ID))
{
string sqlQuery = "select name from userInfo where id = '" + ID + "' ";
string connectionStr = @"Data Source=(local)\SQLEXPRESS;Initial Catalog=aspnetdb;Integrated Security=True;";
using (SqlConnection myCon = new SqlConnection(connectionStr))
{
SqlCommand cmdQuery = new SqlCommand(sqlQuery, myCon);
try
{
myCon.Open();
name = cmdQuery.ExecuteScalar().ToString();
}
catch (Exception ex)
{
throw ex;
}
}
return name;
}
else
{
return "";
}
}
private int Insert(string name)
{
if (name == "")
{
return -1;
}
else
{
string sqlInsert = "Insert into list(mxname) values ('" + name + "') ";
string connectionStr = @"Data Source=(local)\SQLEXPRESS;Initial Catalog=aspnetdb;Integrated Security=True;";
using (SqlConnection myCon = new SqlConnection(connectionStr))
{
SqlCommand cmdInsert = new SqlCommand(sqlInsert);
try
{
myCon.Open();
return cmdInsert.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
}
}
}我没调试,楼主自己调试吧。
调用:
Insert(Query())