使用DataRow["列名"].GetType()看看行不

解决方案 »

  1.   

    用sp_help存储过程
    this.sqlConnection1.Open();
    this.sqlDataAdapter1.SelectCommand.CommandText = "sp_help table1";
    DataSet ds = new DataSet();
    this.sqlDataAdapter1.Fill(ds,"table1");
    this.dataGrid1.DataSource = ds.Tables[1].DefaultView;
    this.sqlConnection1.Close();
    for(int i=0;i<ds.Tables[1].Rows.Count;i++)
    {
    this.listBox1.Items.Add(ds.Tables[1].Rows[i]["type"].ToString());
    }
      

  2.   

    example:SqlConnection conn = new SqlConnection("server=www;database=rascal;uid=xrascal;pwd=");
    string strSelect = "select * from fenye";
    SqlDataAdapter da = new SqlDataAdapter(strSelect,conn);
    DataSet ds = new DataSet();
    da.Fill(ds,"fenye");
    for(int i=0;i<ds.Tables[0].Columns.Count;i++)
    {
                       // 注意这里
                       Response.Write("<br>"+ds.Tables[0].Columns[i].DataType);
    }
      

  3.   

    用sp_help存储过程如果用的不是sql server不就惨了
    Tables[0].Columns[i].DataType这句话得到的是c#中的类型
      

  4.   

    兄弟你想得到什么样的数据类型?
    xrascal(横刀夺爱)的方法是对的啊,先得到C#类型,想得到其他类型可以再转啊!
      

  5.   

    我想要问的是的到了c#类型后,怎样转换成OleDbType类型的,请 gaodz(慕白) 大哥多多帮忙
      

  6.   

    在准确一些就是说如何将DataType转换成OleDbType
      

  7.   

    不过可以比较OleDbType.VarChar.Equals();
      

  8.   

    无论是DataSet,OleDbDataReader 或 SqlDataReader 使用GetFieldType 返回的数据类型都是.net数据类型。解决办法是:
    1 自己建立一个 .net数据类型到相应数据库源数据类型的对照表
    2 正对不同的数据库找到 类似 sp_help tblName 的存储过程,从返回的纪录集获得相应自断的数据类型。本人认为 第2种方案还好一点
      

  9.   

    Private string TypeTranfer(string sDataType)
    {
        switch(sDataType){
            case "Int32":return "Integer";
            case "DataTime":return "Date";
            //...
            case else:return "";
        }
    }
    具体的转换表参照:
    ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfSystemDataOleDbOleDbTypeClassTopic.htm
      

  10.   

    if(DataRow["列名"].GetType()==typeof(System.Int32))
    {
    }