把数据中的数据绑定到dataGridViewX1

  
    
#region 把数据绑定到dataGridViewX1
/// <summary>
///
/// </summary>
/// <param name="RiverName"> 河流名称 </param>
/// <param name="connString"> 数据库连接串 </param>
public void GetRiverString( string RiverName, string connString)
{
SqlConnection conn
= null ;
try
{
conn
= new SqlConnection(connString);
conn.Open();
string SqlStr = " SELECT ID, RIVERCODE, FDKZDMC, KZDHDGC, JSYJQJHC, JSYJHDPD,JSYJQJLYMJZA, JSYJQJLYMJYA, " +
" KZDYSLYMJZA, KZDYSLYMJYA, KZDYSHC, KZDYSHDPD, LSZGSW, LSZGLL,LSZGSJ, BZ " +
" FROM CC_RIVER_JHFDLYTZZ " +
" WHERE (RIVERCODE =' " + RiverName + " ') " ;
SqlCommand cmd
= conn.CreateCommand();
cmd.CommandText
= SqlStr;
SqlDataAdapter da
= new SqlDataAdapter(cmd);
DataSet ds
= new DataSet();
da.Fill(ds);
if (ds.Tables != null && ds.Tables[ 0 ].Rows != null )
{
foreach (DataRow dr in ds.Tables[ 0 ].Rows)
{
if (dr[ " LSZGSW " ].ToString() != "" )
{
dr[
" LSZGSW " ] = Decimal.Parse(dr[ " LSZGSW " ].ToString()).ToString( " 0.00 " );

}
if (dr[ " LSZGLL " ].ToString() != "" )
{
dr[
" LSZGLL " ] = PublicMethod.ConvertEFigure(dr[ " LSZGLL " ].ToString());
}
}
dataGridViewX1.DataSource
= ds.Tables[ 0 ].DefaultView;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
}
#endregion

你可能感兴趣的:(datagridview)