Bind SQL data with SharePoint Gridview
-
02-10-2020 - |
Pregunta
I'm developing a SharePoint solution, In an Application Page, I want to place SPGridView
and I have to bind it with SQL server data.
Is it possible and if yes, how?
Solución
Yes it is possible, here is a basic example:
protected void Page_Load(object sender, EventArgs e) { const string ConnectionString = @"Persist Security Info=False; Integrated Security=SSPI; Server=hercules\sqlexpress;Connect Timeout=30;Database=TestDB;"; SqlConnection con = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlCommand("select * from CustomerTable", con); SqlDataAdapter adp = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adp.Fill(ds); DataTable dt = ds.Tables[0]; gridview1.DataSource = dt.DefaultView; gridview1.DataBind(); }
from here
Otros consejos
yes we can bind data to spgridview same as gridview.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a sharepoint.stackexchange