Build (web): The server tag is not well formed. - this line --->>> <asp:SqlDataSource ID="Resident Details" runat="server" ProviderName="System.Data.SqlClient" ConnectionStrings="<%$ ConnectionStrings:ThisIsTheConnection%>"
and:
Literal expressions like '<%$ ConnectionStrings:ThisIsTheConnection%>' are not allowed. Use <asp:Literal runat="server" Text="<%$ ConnectionStrings:ThisIsTheConnection%>" /> instead.
at this line --->>> <asp:SqlDataSource ID="Resident Details" runat="server" ProviderName="System.Data.SqlClient" ConnectionStrings="<%$ ConnectionStrings:ThisIsTheConnection%>"
It's not true. The syntax with ..."+".."+"... is wrong. It's a Visual Basic thing which is not accepted in the tag writing. Please remove end quotes and plus signs at the end of each line and quotes at the beginning of each line and see what happens.
Marked as answer by Mikesdotnetting on Aug 23, 2010 06:18 PM
Build (web): Type 'System.Web.UI.WebControls.SqlDataSource' does not have a public property named 'ConnectionStrings'
At this line --->>> <asp:SqlDataSource ID="Resident Details" runat="server" ProviderName="System.Data.SqlClient" ConnectionStrings="<%$
ConnectionStrings:ThisIsTheConnection%>"
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" >
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.
vinz
All-Star
126946 Points
17922 Posts
MVP
Re: Unable to make connection to database?
Aug 16, 2010 10:52 AM|LINK
Start looking at: http://www.asp.net/web-forms/data
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
Veschich
Member
29 Points
279 Posts
Re: Unable to make connection to database?
Aug 16, 2010 12:01 PM|LINK
Well there's a lot of info but where to begin? I mean a wrote a code and i think it has to be filled with something not to write it again right?
vinz
All-Star
126946 Points
17922 Posts
MVP
Re: Unable to make connection to database?
Aug 16, 2010 12:25 PM|LINK
Since you are using SqlDataSource then you can start by following this example: http://www.asp.net/data-access/tutorials/inserting-updating-and-deleting-data-with-the-sqldatasource-cs
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
Veschich
Member
29 Points
279 Posts
Re: Unable to make connection to database?
Aug 16, 2010 05:13 PM|LINK
Ok. I'v read again a lot of information, repair my code but still need help. This is my code:
<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"> <UpdateParameters></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="FNAME" Type="String" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="LNAME" Type="String" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="MobileNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="HomeNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="OfficeNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="FaxNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </UpdateParameters></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"> <InsertParameters></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="FNAME" Type="String" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="LNAME" Type="String" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="MobileNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="HomeNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="OfficeNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="FaxNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </InsertParameters></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"> <DeleteParameters></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="FNAME" Type="int" /> </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </DeleteParameters></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"> </asp:SqlDataSource></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"> <br /></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"> <asp:GridView ID="GridView1" runat="server" DataSourceID="Resident Details" AutoGenerateColumns="True" PageSize="10" AllowPaging="True" style="font-family: Verdana"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <Columns></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:BoundField DataField="FNAME" HeaderText="First Name" SortExpression="FNAME" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:BoundField DataField="LNAME" HeaderText="Last Name" SortExpression="LNAME" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:BoundField DataField="MobileNum" HeaderText="Mobile Number" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:BoundField DataField="HomeNum" HeaderText="Home Number" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:BoundField DataField="OfficeNum" HeaderText="Office Number" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:BoundField DataField="FaxNum" HeaderText="Fax Number" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:CommandField ShowEditButton="True" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:CommandField ShowDeleteButton="True" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:CommandField ShowInsertButton="True" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </Columns></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </asp:GridView></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" >
<UpdateParameters>
<asp:Parameter Name="FNAME" Type="String" />
<asp:Parameter Name="LNAME" Type="String" />
<asp:Parameter Name="MobileNum" Type="Int" />
<asp:Parameter Name="HomeNum" Type="Int" />
<asp:Parameter Name="OfficeNum" Type="Int" />
<asp:Parameter Name="FaxNum" Type="Int" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="FNAME" Type="String" />
<asp:Parameter Name="LNAME" Type="String" />
<asp:Parameter Name="MobileNum" Type="Int" />
<asp:Parameter Name="HomeNum" Type="Int" />
<asp:Parameter Name="OfficeNum" Type="Int" />
<asp:Parameter Name="FaxNum" Type="Int" />
</InsertParameters>
<DeleteParameters>
<asp:Parameter Name="FNAME" Type="int" />
</DeleteParameters>
</asp:SqlDataSource>
<br />
<asp:GridView ID="GridView1" runat="server" DataSourceID="Resident Details" AutoGenerateColumns="True" PageSize="10" AllowPaging="True" style="font-family: Verdana">
<Columns>
<asp:BoundField DataField="FNAME" HeaderText="First Name" SortExpression="FNAME" />
<asp:BoundField DataField="LNAME" HeaderText="Last Name" SortExpression="LNAME" />
<asp:BoundField DataField="MobileNum" HeaderText="Mobile Number" />
<asp:BoundField DataField="HomeNum" HeaderText="Home Number" />
<asp:BoundField DataField="OfficeNum" HeaderText="Office Number" />
<asp:BoundField DataField="FaxNum" HeaderText="Fax Number" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
<asp:CommandField ShowInsertButton="True" />
</Columns>
</asp:GridView>
And here's the errors it gain:
Build (web): The server tag is not well formed. - this line --->>> <asp:SqlDataSource ID="Resident Details" runat="server" ProviderName="System.Data.SqlClient" ConnectionStrings="<%$ ConnectionStrings:ThisIsTheConnection%>"
and:
Literal expressions like '<%$ ConnectionStrings:ThisIsTheConnection%>' are not allowed. Use <asp:Literal runat="server" Text="<%$ ConnectionStrings:ThisIsTheConnection%>" /> instead.
at this line --->>> <asp:SqlDataSource ID="Resident Details" runat="server" ProviderName="System.Data.SqlClient" ConnectionStrings="<%$ ConnectionStrings:ThisIsTheConnection%>"
Any guesses???
smirnov
All-Star
23586 Points
4049 Posts
Re: Unable to make connection to database?
Aug 16, 2010 05:34 PM|LINK
You may not concatenate the strings in UpdateCommand, InsertCommand and DeleteCommand properties in this way. The right syntax is
(no ..."+"..."+"...)
Hope this helps.
a2baghdanian
Member
25 Points
19 Posts
Re: Unable to make connection to database?
Aug 16, 2010 06:07 PM|LINK
Why are you using "+" to concatenate the rows.
Do not use "+".
Do it like this:
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"
"UpdateCommand" tag color will become red and the rest will become blue color.
Hope this will help you.
Veschich
Member
29 Points
279 Posts
Re: Unable to make connection to database?
Aug 16, 2010 06:09 PM|LINK
as far as i understand this is for better viewing because i think:
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">"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>"UPDATE Resident SET FNAME=@FNAME, LNAME=@LNAME, OfficeNum=@OfficeNum" +
"FaxNum=@FaxNum"
in two lines is equal as:
"UPDATE Resident SET FNAME=@FNAME, LNAME=@LNAME, " OfficeNum=@OfficeNum, FaxNum=@FaxNum"
in only one.
I think the problem is somewhere else. Plus that for now i don't connect Button1 with the SqlDataSource so may be here's the problem?
smirnov
All-Star
23586 Points
4049 Posts
Re: Unable to make connection to database?
Aug 16, 2010 10:32 PM|LINK
It's not true. The syntax with ..."+".."+"... is wrong. It's a Visual Basic thing which is not accepted in the tag writing. Please remove end quotes and plus signs at the end of each line and quotes at the beginning of each line and see what happens.
Veschich
Member
29 Points
279 Posts
Re: Unable to make connection to database?
Aug 17, 2010 08:15 PM|LINK
You are right. I fix this but now this happen:
Build (web): Type 'System.Web.UI.WebControls.SqlDataSource' does not have a public property named 'ConnectionStrings'
At this line --->>> <asp:SqlDataSource ID="Resident Details" runat="server" ProviderName="System.Data.SqlClient" ConnectionStrings="<%$ ConnectionStrings:ThisIsTheConnection%>"
<div></div>
<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"></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, 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"</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 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"</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, 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" ></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"> <UpdateParameters></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="FNAME" Type="String" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="LNAME" Type="String" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="MobileNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="HomeNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="OfficeNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="FaxNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </UpdateParameters></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"> <InsertParameters></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="FNAME" Type="String" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="LNAME" Type="String" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="MobileNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="HomeNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="OfficeNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="FaxNum" Type="Int" /></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </InsertParameters></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"> <DeleteParameters></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:Parameter Name="FNAME" Type="int" /> </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </DeleteParameters></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"> </asp:SqlDataSource></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"> <br /></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" >
<UpdateParameters>
<asp:Parameter Name="FNAME" Type="String" />
<asp:Parameter Name="LNAME" Type="String" />
<asp:Parameter Name="MobileNum" Type="Int" />
<asp:Parameter Name="HomeNum" Type="Int" />
<asp:Parameter Name="OfficeNum" Type="Int" />
<asp:Parameter Name="FaxNum" Type="Int" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="FNAME" Type="String" />
<asp:Parameter Name="LNAME" Type="String" />
<asp:Parameter Name="MobileNum" Type="Int" />
<asp:Parameter Name="HomeNum" Type="Int" />
<asp:Parameter Name="OfficeNum" Type="Int" />
<asp:Parameter Name="FaxNum" Type="Int" />
</InsertParameters>
<DeleteParameters>
<asp:Parameter Name="FNAME" Type="int" />
</DeleteParameters>
</asp:SqlDataSource>
<br />
And i have this in web.config:
<add name="ThisIsMyConnection"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
????