reate new database: SQLConnectorSharepoint
Create new Table in database
SQLConnectorSharepoint with name is Products
Create new columns: ID, Name, Price
Enter some data:
Open Visual studio 2010 | New Project | Empty
Sharepoint Project | Name is DisplaySQLTableToSP
Deploy as a farm solution
Right click Project | Add new item | Visual Web
Part | Name is DisPlaySQLTableToSP
User
Interface (UI) follows as:
Copy code here to below
<asp:LiteralID="literalID"runat="server"></asp:Literal>
<asp:LiteralID="literalName"runat="server"></asp:Literal>
<asp:LiteralID="literalPrice"runat="server"></asp:Literal>
Now, turn on view code to develop
Code in event page_load
Using
usingSystem.Data.SqlClient;
usingSystem.Data;
Paste this code to event Page_Load
try
{
stringconnectionString
= "Data Source=.;Initial
Catalog=SQLConnectorSharepoint ;Integrated Security=True";
string query = "SELECT ID, Name, Price FROM Products WHERE
ID=(SELECT MAX(ID) from Products)";
SqlDataAdapter da
= newSqlDataAdapter(query,
connectionString);
DataTabletableProducts = newDataTable();
da.Fill(tableProducts);
if (tableProducts.Rows.Count>0)
{
literalID.Text = tableProducts.Rows[0]["ID"].ToString();
literalName.Text = tableProducts.Rows[0]["Name"].ToString();
literalPrice.Text = Convert.ToString(tableProducts.Rows[0]["Price"]);
}
}
catch (Exception ex)
{
Response.Write("Exception:
" + ex.Message);
}
}
Open your sharepoint and add webpart, you will
see result follows as:
Add caption |
It's in point of fact a nice and useful piece of information. I'm satisfied that you
ReplyDeletejust shared this useful information with us. Please keep us informed
like this. Thanks for sharing.
My website :: seen on tv slimmer shaper