我是用一个DataGrid空间绑定了一个超级连接列,绑定的是cnat_id然后提交到另一个页面去修改!也就是提交到添加的页面去修改让数据显示在TextBox中,数据库一共11个字段。DBCon是一个链接类,数据库主键字段也叫cnat_id下一步改怎么弄呀才能让数据显示在TextBox中
string cnat_id=Request.QueryString["cnat_id"].ToString();
SqlConnection con=DBCon.createCon();
SqlCommand cnd=new SqlCommand("select jgsj from cnatword where cnat_id=cnat_id",con);

解决方案 »

  1.   

    把SqlCommand cnd=new SqlCommand("select jgsj from cnatword where cnat_id=cnat_id",con);换成
    SqlDataAdapter sda = new SqlDataAdapter(("select jgsj from cnatword where cnat_id=cnat_id",con);
    DataTable dt = new DataTable;
    sda.Fill(dt);
    TextBox.Text = dt.rows[行数][列数].tostring();
      

  2.   

    SqlDataAdapter sda= new SqlDataAdapter("select jgsj from cnatword where cnat_id=cnat_id",con);
    DataSet ds=new DataSet();
    ds.Fill(sda);
    this.TextBox1.Text=ds.Tables[0]["你的字段"].ToString();
      

  3.   

    ds.Fill(sda);不好意思,写反了,sda.fill(ds);
      

  4.   

    TextBox.Text = dt.rows[行数][列数].tostring();
    行数列数指的是什么?我新手不太明白!!也比较笨!
      

  5.   

    this.TextBox1.Text=ds.Tables[0].Row["你的字段"].ToString();
      

  6.   

    晕,没写在vs上写,老是写错,Row改成Rows
      

  7.   

    ds.Fill(sda);  换成   sda.fill(ds);   对吗?
      

  8.   

    我要显示的字段是jgsj 
    ("select jgsj from cnatword where cnat_id=cnat_id",con);但是我把字段名称写进去运行的时候它说我
    C:\Inetpub\wwwroot\cnat_work\index.aspx.cs(75): 名称“jgsj”在类或命名空间“cnat_work.index”中不存在
    着是怎么了?
      

  9.   

    using System.Data.SqlClient;你加了没有?
      

  10.   

    还有,你这个("select jgsj from cnatword where cnat_id=cnat_id",con);要这样写:
    ("select jgsj from cnatword where cnat_id='"+cnat_id+"'",con);
      

  11.   

    this.cnat_x1.Checked=dt.Rows[2]["sfzp"].ToString();
    如果是单选按妞着句该怎么写呢!????
      

  12.   

    我的小例子有个单选择按钮 比方说 男和女 两者选择一项!
    this.cnat_x1.Checked=dt.Rows[2]["sfzp"].ToString();
    这句该怎么写?????
      

  13.   

    你是说选择单选择按钮后把值显示在文本框中是这意思把
    if(!IsPostBack)
    {
    this.cnat_x1.autopostback = true;
    }
    然后在单选择按钮的事件中把值赋给文本框就行了
      

  14.   

    我在表达一次!
    我的意思是说我的小例子比方说!就一个单选择按钮 是的话就选择 不是的话就不选择 我在添加的时候是这样判断的写如数据库的
    if(this.cnat_x1.Checked)
    {
    p.cnat_x1="是";
    }
    else
    {
    p.cnat_x1="";
    }
    修改的时候!得显示选中状态!
      

  15.   

    根据sfzp字段来判断单选择按钮是否选中?
    if(dt.Rows[2]["sfzp"].ToString().Equals("是")
    {
    this.cnat_x1.Checked = true;
    }
    else
    {
    this.cnat_x1.Checked = false;
    }
      

  16.   

    if(dt.Rows[22]["ywpj"].ToString().Equals("优"))
    {
    this.cnat_x2.Checked = true;
    }
    else
    {
    this.cnat_x2.Checked = false;
    } if(dt.Rows[23]["ywpj"].ToString().Equals("良"))
    {
    this.cnat_x3.Checked = true;
    }
    else
    {
    this.cnat_x3.Checked = false;
    }
    if(dt.Rows[24]["ywpj"].ToString().Equals("差"))
    {
    this.cnat_x4.Checked = true;
    }
    else
    {
    this.cnat_x4.Checked = false;
    }
    如果是评价优良差呢!我该怎么判断吗?但是显示错误呀!
      

  17.   

    我写入数据库的时候是这样判断的
    if(this.cnat_x2.Checked)
    {
    p.pj="优";
    }
    if(this.cnat_x3.Checked)
    {
    p.pj="良";
    }
    if(this.cnat_x4.Checked)
    {
    p.pj="差";
    }
      

  18.   

    this.TextBox1.Text=ds.Tables[0]["jgsj"].ToString();
      

  19.   

    if(dt.Rows[24]["ywpj"].ToString().Equals("差"))
    不用Equals,用if(dt.Rows[24]["ywpj"].ToString()=="差")
      

  20.   

    现在都已经显示出来了!但是又出现了问题!this.cnat_1.Text=dt.Rows[0]["jgsj"].ToString();
    第零列
    但是我有很多数据显示的都是第零的!改怎么办?
      

  21.   

    dt.Rows[0]["jgsj"].ToString();0是第1行,而不是第1列,["jgsj"]才是列
      

  22.   

    不是我的意思是this.cnat_1.Text=dt.Rows[0]["jgsj"].ToString();
    我数据库中有很多行数据!现在都显示的是第0行的数据!我怎么才能让他按照这个传进去的数据库的主键显示正确的行数里的数据呢?
    string cnat_id=Request.QueryString["cnat_id"].ToString();
      

  23.   

    是实验过了!但是在程序正式完成了以后!我不可能一次一次的调呀!!
    比方说我着个例子要上传网上!在网上添加数据然后写入数据库!我想让我的DataGrid绑定的超级连接列点进去之后按照数据库中的主键查找相对的数据写入相对TEXTBOX中!~
      

  24.   

    什么意思呀?那着个地方this.cnat_1.Text=dt.Rows[0]["jgsj"].ToString();
    行号我改怎么写才能按照我提交出去的主键查找到呢!