Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Member
29 Points
279 Posts
Aug 16, 2010 09:24 AM|LINK
Hy guys. I try to connect my database for so long so i wrote two type of codes. Let's discuse first on.
I have database called PhoneDirectory.
It have only one table named Residents.
I have button wiht ID="Button1".
I want when i click this button to see all of my residents.
I want to see the result in DetailsView and to be able to edin, delete and add new resident.
First try with SqlDataSource so i wrote this:
<asp:SqlDataSource ID="Resident Details" runat="server" ProviderName="System.Data.SqlClient" ConnectionStrings="<%$ ConnectionStrings:ThisIsTheConnection%>"
SelectCommand = "SELECT * FROM Resident "
UpdateCommand = "UPDATE Resident SET FNAME=@FNAME, LNAME=@LNAME, MobileNum=@MobileNum," +
"HomeNum=@HomeNum, OfficeNum=@OfficeNum, FaxNum=@FaxNum" +
"WHERE FNAME=@original_FNAME AND LNAME=@original_LNAME AND MobileNum=@original_MobileNum" +
"HomeNum=@original_HomeNum AND OfficeNum=@original_OfficeNum AND FaxNum=@original_FaxNum"
InsertCommand = "INSERT INTO Resident FNAME, LNAME, MobileNum, HomeNum, OfficeNum, FaxNum" +
"VALUES ( '@FNAME', '@LNAME', '@MobileNum', '@HomeNum', '@OfficeNum', '@FaxNum')" +
DeleteCommand = "DELETE Resident WHERE FNAME=@FNAME, LNAME=@LNAME, MobileNum=@MobileNum," +
"HomeNum=@original_HomeNum AND OfficeNum=@original_OfficeNum AND FaxNum=@original_FaxNum" >
</asp:SqlDataSource>
For the DetailsView - >
<asp:DetailsView ID="Resident Details" runat="server" Height="50px" Width="125px" DataSourceID="Resident Details">
</asp:DetailsView>
And now i don't know how to bind all these 3 things. Please help.
P.S. I guess i miss something in SqlDataSource like Parameters but i'm not sure what to add.
I use Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional, Second Edition for this.
Veschich
Member
29 Points
279 Posts
Unable to make connection to database?
Aug 16, 2010 09:24 AM|LINK
Hy guys. I try to connect my database for so long so i wrote two type of codes. Let's discuse first on.
I have database called PhoneDirectory.
It have only one table named Residents.
I have button wiht ID="Button1".
I want when i click this button to see all of my residents.
I want to see the result in DetailsView and to be able to edin, delete and add new resident.
First try with SqlDataSource so i wrote this:
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"><asp:SqlDataSource ID="Resident Details" runat="server" ProviderName="System.Data.SqlClient" ConnectionStrings="<%$ ConnectionStrings:ThisIsTheConnection%>" </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> SelectCommand = "SELECT * FROM Resident "</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> UpdateCommand = "UPDATE Resident SET FNAME=@FNAME, LNAME=@LNAME, MobileNum=@MobileNum," +</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> "HomeNum=@HomeNum, OfficeNum=@OfficeNum, FaxNum=@FaxNum" + </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> "WHERE FNAME=@original_FNAME AND LNAME=@original_LNAME AND MobileNum=@original_MobileNum" +</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> "HomeNum=@original_HomeNum AND OfficeNum=@original_OfficeNum AND FaxNum=@original_FaxNum"</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> InsertCommand = "INSERT INTO Resident FNAME, LNAME, MobileNum, HomeNum, OfficeNum, FaxNum" + </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> "VALUES ( '@FNAME', '@LNAME', '@MobileNum', '@HomeNum', '@OfficeNum', '@FaxNum')" + </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> "WHERE FNAME=@original_FNAME AND LNAME=@original_LNAME AND MobileNum=@original_MobileNum" +</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> "HomeNum=@original_HomeNum AND OfficeNum=@original_OfficeNum AND FaxNum=@original_FaxNum"</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> DeleteCommand = "DELETE Resident WHERE FNAME=@FNAME, LNAME=@LNAME, MobileNum=@MobileNum," +</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> "HomeNum=@HomeNum, OfficeNum=@OfficeNum, FaxNum=@FaxNum" + </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> "WHERE FNAME=@original_FNAME AND LNAME=@original_LNAME AND MobileNum=@original_MobileNum" +</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> "HomeNum=@original_HomeNum AND OfficeNum=@original_OfficeNum AND FaxNum=@original_FaxNum" ></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <SelectParameters></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:ControlParameter ControlID="Resident Details" Name="ProductID" PropertyName="SelectedValue" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </SelectParameters></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </asp:SqlDataSource></div><asp:SqlDataSource ID="Resident Details" runat="server" ProviderName="System.Data.SqlClient" ConnectionStrings="<%$ ConnectionStrings:ThisIsTheConnection%>"
SelectCommand = "SELECT * FROM Resident "
UpdateCommand = "UPDATE Resident SET FNAME=@FNAME, LNAME=@LNAME, MobileNum=@MobileNum," +
"HomeNum=@HomeNum, OfficeNum=@OfficeNum, FaxNum=@FaxNum" +
"WHERE FNAME=@original_FNAME AND LNAME=@original_LNAME AND MobileNum=@original_MobileNum" +
"HomeNum=@original_HomeNum AND OfficeNum=@original_OfficeNum AND FaxNum=@original_FaxNum"
InsertCommand = "INSERT INTO Resident FNAME, LNAME, MobileNum, HomeNum, OfficeNum, FaxNum" +
"VALUES ( '@FNAME', '@LNAME', '@MobileNum', '@HomeNum', '@OfficeNum', '@FaxNum')" +
"WHERE FNAME=@original_FNAME AND LNAME=@original_LNAME AND MobileNum=@original_MobileNum" +
"HomeNum=@original_HomeNum AND OfficeNum=@original_OfficeNum AND FaxNum=@original_FaxNum"
DeleteCommand = "DELETE Resident WHERE FNAME=@FNAME, LNAME=@LNAME, MobileNum=@MobileNum," +
"HomeNum=@HomeNum, OfficeNum=@OfficeNum, FaxNum=@FaxNum" +
"WHERE FNAME=@original_FNAME AND LNAME=@original_LNAME AND MobileNum=@original_MobileNum" +
"HomeNum=@original_HomeNum AND OfficeNum=@original_OfficeNum AND FaxNum=@original_FaxNum" >
</asp:SqlDataSource>
For the DetailsView - >
<asp:DetailsView ID="Resident Details" runat="server" Height="50px" Width="125px" DataSourceID="Resident Details">
</asp:DetailsView>
And now i don't know how to bind all these 3 things. Please help.
P.S. I guess i miss something in SqlDataSource like Parameters but i'm not sure what to add.
I use Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional, Second Edition for this.