根据参数在userInfo表中查询等于参数的那条数据
select name from userInfo where id=" + Request.QueryString["id"].ToString() + "写入到list表中
select * from list如何写cs代码,谢谢

解决方案 »

  1.   

    select name from userInfo where id=" + Request.QueryString["id"].ToString() + " 
    --
    千万不要这样写。
    首先要判断if(!string.isnullorEmpty(Request.QueryString["id"]))
    2.还要把int id=int.parse(Request.QueryString["id"].ToString())
    3.最好以参数形式进去。关于怎么执行sql然后填充到一个DataTable中,你可以去看看一些开源的SqlHelper。
      

  2.   

    能帮我写下代码吗?
    sql数据库的
    就把userInfo表中的name写入到list这个字段的mxname里去
      

  3.   


    if(!string.isnullorEmpty(Request.QueryString["id"])) 
    {
      int aa=int.parse(Request.QueryString["id"].ToString());
      string sql = "select name from userInfo where id = aa";
    }
      

  4.   

    insert into list(mxname) select name from userInfo where id=" + uiduid就是你获得的uid = Request.QueryString["id"].ToString()
      

  5.   


    说实话,“list这个字段的mxname”是嘛玩意儿?我真没看懂!
      

  6.   

    这个写的就是我的意思
    但是报错是什么原因呢》
    行 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 
      

  7.   

    编译器错误信息: CS1010: 常量中有换行符源错误: 行 35:                 //this.mxname.Value = dt.Rows[0]["mxname"].ToString();
    行 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 
      

  8.   

    执行这个sql不就可以了吗
    insert into list(mxname) select name from userInfo where id=" + uid 
    uid就是你获得的uid = Request.QueryString["id"].ToString()你不就是根据id找一个表中的信息插入到另外一个表中啊?
      

  9.   

    不好意思string strSQL = "insert into list(mxname) select name from userInfo where id=" + uid 执行这个sql就行了。
      

  10.   

    汗。。你连一个底层方法都没有,就直接写sql在页面后台文件》?这个后台文件不是sql server 管理器。。看看书吧。看看ADO.net
      

  11.   

    .net最基础的东西。1.连接数据库,实现表的增删改。。如果你连这几个都不会,那赶快去看书
      

  12.   

    的确没错,是基本功。
    大家估计很忙,让我这个裤衩帮你解决吧:
    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())
      

  13.   

    http://blog.csdn.net/xianfajushi/archive/2009/11/02/4581138.aspx