User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 392,047 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,290 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 817 | Replies: 1
Reply
Join Date: May 2008
Posts: 23
Reputation: fayenot is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
fayenot fayenot is offline Offline
Newbie Poster

Must declare the scalar variable ERROR

  #1  
Jun 1st, 2008
can anyone tell me what's wrong with my codes below..what does this error mean and how can i get rid of it...looking forward for your help..

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head runat="server">
  7. <title>Untitled Page</title>
  8. </head>
  9. <body>
  10. <form id="form1" runat="server">
  11.  
  12. <h3>FormView Example</h3>
  13.  
  14. <table cellspacing="10">
  15.  
  16. <tr>
  17. <td>
  18. <asp:GridView ID="ClientGridView"
  19. DataSourceID="ClientSqlDataSource"
  20. AutoGenerateColumns="false"
  21. DataKeyNames="ClientID"
  22. OnSelectedIndexChanged="ClientGridView_OnSelectedIndexChanged"
  23. RunAt="Server">
  24.  
  25. <HeaderStyle backcolor="Navy"
  26. forecolor="White" />
  27.  
  28. <Columns>
  29.  
  30. <asp:ButtonField Text="Details..."
  31. HeaderText="Show<BR>Details"
  32. CommandName="Select"/>
  33.  
  34. <asp:BoundField DataField="ClientName" HeaderText="Client Name"/>
  35. <asp:BoundField DataField="Address" HeaderText="Address"/>
  36. <asp:BoundField DataField="ContactPerson" HeaderText="Contact Person"/>
  37.  
  38. </Columns>
  39.  
  40. </asp:GridView>
  41.  
  42. </td>
  43.  
  44. <td valign="top">
  45.  
  46. <asp:FormView ID="ClientFormView"
  47. DataSourceID="ClientSqlDataSource"
  48. DataKeyNames="ClientID"
  49. Gridlines="Both"
  50. OnItemUpdated="ClientFormView_ItemUpdated"
  51. OnItemDeleted="ClientFormView_ItemDeleted"
  52. RunAt="server">
  53.  
  54. <HeaderStyle backcolor="Navy"
  55. forecolor="White"/>
  56.  
  57. <RowStyle backcolor="White"/>
  58.  
  59. <EditRowStyle backcolor="LightCyan"/>
  60.  
  61. <ItemTemplate>
  62. <table>
  63. <tr><td align="right"><b>Client ID:</b></td><td><%# Eval("ClientId") %></td></tr>
  64. <tr><td align="right"><b>Client Name:</b></td> <td><%# Eval("ClientName") %></td></tr>
  65. <tr><td align="right"><b>Address:</b></td> <td><%# Eval("Address") %></td></tr>
  66. <tr><td align="right"><b>Contact Person:</b></td> <td><%# Eval("ContactPerson") %></td></tr>
  67. <tr><td align="right"><b>Telephone No.:</b></td> <td><%# Eval("TelNo") %></td></tr>
  68. <tr><td align="right"><b>Email:</b></td> <td><%# Eval("Email") %></td></tr>
  69. <tr>
  70. <td colspan="2">
  71. <asp:LinkButton ID="EditButton"
  72. Text="Edit"
  73. CommandName="Edit"
  74. RunAt="server"/>
  75. &nbsp;
  76. <asp:LinkButton ID="NewButton"
  77. Text="New"
  78. CommandName="New"
  79. RunAt="server"/>
  80. &nbsp;
  81. <asp:LinkButton ID="DeleteButton"
  82. Text="Delete"
  83. CommandName="Delete"
  84. RunAt="server"/>
  85. </td>
  86. </tr>
  87. </table>
  88. </ItemTemplate>
  89.  
  90. <EditItemTemplate>
  91. <table>
  92.  
  93. <tr><td align="right"><b>User:</b></td>
  94. <td><asp:TextBox ID="UserTextBox"
  95. Text='<%# Bind("UserId") %>'
  96. RunAt="Server" /></td></tr>
  97.  
  98.  
  99. <tr><td align="right"><b>Project:</b></td>
  100. <td><asp:TextBox ID="ProjectTextBox"
  101. Text='<%# Bind("ProjectId") %>'
  102. RunAt="Server" /></td></tr>
  103.  
  104. <tr><td align="right"><b>Client Name:</b></td>
  105. <td><asp:TextBox ID="EditClientNameTextBox"
  106. Text='<%# Bind("ClientName") %>'
  107. RunAt="Server" /></td></tr>
  108.  
  109. <tr><td align="right"><b>Address:</b></td>
  110. <td><asp:TextBox ID="EditAddressTextBox"
  111. Text='<%# Bind("Address") %>'
  112. RunAt="Server" /></td></tr>
  113.  
  114.  
  115. <tr><td align="right"><b>Contact Person:</b></td>
  116. <td><asp:TextBox ID="EditContactPersonTextBox"
  117. Text='<%# Bind("ContactPerson") %>'
  118. RunAt="Server" /></td></tr>
  119.  
  120. <tr><td align="right"><b>Telephone Number:</b></td>
  121. <td><asp:TextBox ID="EditTelNoTextBox"
  122. Text='<%# Bind("TelNo") %>'
  123. RunAt="Server" /></td></tr>
  124.  
  125. <tr><td align="right"><b>Email:</b></td>
  126. <td><asp:TextBox ID="EditEmailTextBox"
  127. Text='<%# Bind("Email") %>'
  128. RunAt="Server" /></td></tr>
  129. <tr>
  130. <td colspan="2">
  131. <asp:LinkButton ID="UpdateButton"
  132. Text="Update"
  133. CommandName="Update"
  134. RunAt="server"/>
  135. &nbsp;
  136. <asp:LinkButton ID="CancelUpdateButton"
  137. Text="Cancel"
  138. CommandName="Cancel"
  139. RunAt="server"/>
  140. </td>
  141. </tr>
  142. </table>
  143. </EditItemTemplate>
  144.  
  145. <InsertItemTemplate>
  146. <table>
  147.  
  148. <tr><td align="right"><b>User:</b></td>
  149. <td><asp:TextBox ID="UserTextBox"
  150. Text='<%# Bind("UserId") %>'
  151. RunAt="Server" /></td></tr>
  152.  
  153. <tr><td align="right"><b>Project:</b></td>
  154. <td><asp:TextBox ID="ProjectTextBox"
  155. Text='<%# Bind("ProjectId") %>'
  156. RunAt="Server" /></td></tr>
  157.  
  158. <tr><td align="right"><b>Client Name:</b></td>
  159. <td><asp:TextBox ID="EditClientNameTextBox"
  160. Text='<%# Bind("ClientName") %>'
  161. RunAt="Server" /></td></tr>
  162.  
  163. <tr><td align="right"><b>Address:</b></td>
  164. <td><asp:TextBox ID="EditAddressTextBox"
  165. Text='<%# Bind("Address") %>'
  166. RunAt="Server" /></td></tr>
  167.  
  168.  
  169. <tr><td align="right"><b>Contact Person:</b></td>
  170. <td><asp:TextBox ID="EditContactPersonTextBox"
  171. Text='<%# Bind("ContactPerson") %>'
  172. RunAt="Server" /></td></tr>
  173.  
  174. <tr><td align="right"><b>Telephone Number:</b></td>
  175. <td><asp:TextBox ID="EditTelNoTextBox"
  176. Text='<%# Bind("TelNo") %>'
  177. RunAt="Server" /></td></tr>
  178.  
  179. <tr><td align="right"><b>Email:</b></td>
  180. <td><asp:TextBox ID="EditEmailTextBox"
  181. Text='<%# Bind("Email") %>'
  182. RunAt="Server" /></td></tr>
  183.  
  184. <tr>
  185. <td colspan="2">
  186. <asp:LinkButton ID="InsertButton"
  187. Text="Insert"
  188. CommandName="Insert"
  189. RunAt="server"/>
  190. &nbsp;
  191. <asp:LinkButton ID="CancelInsertButton"
  192. Text="Cancel"
  193. CommandName="Cancel"
  194. RunAt="server"/>
  195. </td>
  196. </tr>
  197. </table>
  198. </InsertItemTemplate>
  199.  
  200. </asp:FormView>
  201.  
  202. </td>
  203.  
  204. </tr>
  205.  
  206. </table>
  207.  
  208. <asp:sqlDataSource ID="ClientSqlDataSource"
  209. selectCommand="SELECT * FROM [Client] WHERE ([UserId]= @UserId)"
  210. InsertCommand="INSERT INTO Client(UserId, ProjectId, ClientName, Address, ContactPerson, TelNo, Email) VALUES (@ProjectId, @ClientName, @Address, @ContactPerson, @TelNo, @Email);
  211. SELECT @ClientId = SCOPE_IDENTITY()"
  212. UpdateCommand="UPDATE Client SET UserId=@UserId, ProjectId=@ProjectId, ClientName=@ClientName, Address=@Address, ContactPerson=@ContactPerson, TelNo=@TelNo, Email=@Email
  213. WHERE ClientId=@ClientId"
  214. DeleteCommand="DELETE Client WHERE ClientId=@ClientId"
  215. connectionstring="<%$ ConnectionStrings:TrialConnectionString %>"
  216. RunAt="server" oninserted="ClientqlDataSource_Inserted">
  217. <SelectParameters>
  218. <asp:Parameter Name="ClientId" Type="Int32" DefaultValue="0" />
  219. </SelectParameters>
  220.  
  221. <InsertParameters>
  222. <asp:Parameter Name="ClientId" Direction="Output" Type="Int32" DefaultValue="0" />
  223. </InsertParameters>
  224.  
  225. </asp:sqlDataSource>
  226.  
  227. </form>
  228. </body>
  229. </html>
  230.  
  231.  
  232.  
  233. protected void ClientGridView_OnSelectedIndexChanged(object sender, EventArgs e)
  234. {
  235. ClientSqlDataSource.SelectParameters["ClientId"].DefaultValue =
  236. ClientGridView.SelectedValue.ToString();
  237. ClientFormView.DataBind();
  238. }
  239. protected void ClientFormView_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
  240. {
  241. ClientGridView.DataBind();
  242. }
  243. protected void ClientFormView_ItemDeleted(object sender, FormViewDeletedEventArgs e)
  244. {
  245. ClientGridView.DataBind();
  246. }
  247. protected void ClientqlDataSource_Inserted(object sender, SqlDataSourceStatusEventArgs e)
  248. {
  249. System.Data.Common.DbCommand command = e.Command;
  250.  
  251. ClientSqlDataSource.SelectParameters["ClientId"].DefaultValue =
  252. command.Parameters["@ClientId"].Value.ToString();
  253.  
  254. ClientGridView.DataBind();
  255. ClientFormView.DataBind();
  256. }
Last edited by peter_budo : Jun 4th, 2008 at 3:31 am. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,123
Reputation: majestic0110 is on a distinguished road 
Rep Power: 3
Solved Threads: 47
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Veteran Poster

Re: Must declare the scalar variable ERROR

  #2  
Jun 1st, 2008
Hi there fayenot, could you please post the exact error message? I have come across this one before myself I think. Also please use code tags
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 11:21 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC