Thursday, November 11, 2021

Grid view from Remote database connectivity in asp.net C#

 web.config

<configuration>

  <connectionStrings>

  <add name="connectionStringCSD" connectionString="initial catalog=csd;user=csd;password=654664;data source=10.500.2.9" />

  </connectionStrings>

</configuration>

-------------------------------*********************---------------------------------

UI

<div>

            <asp:GridView ID="GridView1" runat="server">

            </asp:GridView>

        </div>

---------------------------***********************------------------------------------

asp.net code for connectivity

 protected void Page_Load(object sender, EventArgs e)

    {

        String conStr = ConfigurationManager.ConnectionStrings["connectionStringCSD"].ConnectionString;


        using (SqlConnection con = new SqlConnection(conStr))

        {

            using (SqlCommand cmd = new SqlCommand("Select TOP 10 * from db_accessadmin.SURVEY_MASTER_DATA_FILE_CORE", con))

            {

                using (SqlDataAdapter da = new SqlDataAdapter(cmd))

                {

                    DataTable dt = new DataTable();

                    da.Fill(dt);

                    GridView1.DataSource = dt;

                    GridView1.DataBind();


                }

            }

        }

    }

No comments:

Post a Comment