CodeVerge.Net Beta
Login Idy
Register Password
  Forgot?
Explore    Item Entry    Members   
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML





Zone: > NEWSGROUP > Asp.Net Forum > starter_kits_and_source_projects.personal_site_starter_kit Tags:
Item Type: NewsGroup Date Entered: 7/20/2006 6:52:13 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 8 Views: 10 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
9 Items, 1 Pages 1 |< << Go >> >|
gridview
Asp.Net User
InsertParameters element ?7/20/2006 6:52:13 PM

0/0

I know :

Parameters can be passed (to database to retrieve data)

using a SelectParameters element.

 

Is this also  true ? :

values can be inserted in database using a InsertParameter element

jwadsworth
Asp.Net User
Re: InsertParameters element ?7/20/2006 8:29:07 PM

0/0

If your referring to the ObjectDataSource here is an example:

<asp:ObjectDataSource ID="ObjectDataSourceBlogEntries" Runat="server"    
     TypeName
="BlogManager"    SelectMethod="GetBlogEntries" InsertMethod="AddBlogEntry">
      
<SelectParameters>
         
<asp:SessionParameter DefaultValue=""
            
Name="category"
            
Direction="input"
            
SessionField="blogcategory"
            
Type="string"
            
ConvertEmptyStringToNull="false" />
         
</SelectParameters>
      
<InsertParameters>
         
<asp:SessionParameter DefaultValue=""
            
Name="category"
            
Direction="Input"
            
SessionField="blogcategory"
            
Type="string"
            
ConvertEmptyStringToNull="false" />
      </InsertParameters>
</asp:ObjectDataSource>

Note that in this example I am setting a session variable in code that is used. The GetBlogEntries and AddBlogEntry procedures must accept a value of type string. I have them both as optional values set to a blank string, such as:

 

Public Shared Function GetBlogEntries(Optional ByVal Category As String = "") As Generic.List(Of Blog)
   
Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("Personal").ConnectionString)

      Dim strSPROC As String = ""
      
If Category.Trim = "" Then
         
strSPROC = "blog_GetBlogEntries"
      
Else
         
strSPROC = "blog_GetBlogEntriesByCategory"
      
End If

      Using command As New SqlCommand(strSPROC, connection)
command.CommandType = CommandType.StoredProcedure
         
connection.Open()
         
If Category.Trim <> "" Then command.Parameters.Add(New SqlParameter("@Category", Category))
            
Dim list As New Generic.List(Of Blog)()
            
Using reader As SqlDataReader = command.ExecuteReader()
               
Do While (reader.Read())
                  
Dim temp As New Blog(CInt(reader("EntryID")), CStr(reader("Category")), CStr(reader("EntryTitle")), CStr(reader("EntryText")), CStr(reader("UserName")), CDate(reader("DateCreated")), CInt(reader("IsDeleted")), CInt(reader("CommentCount")))

                  list.Add(temp)
               

Loop
            
End Using
            
Return list
         
End Using
   
End Using
End Function

Jeremy

Extended Personal Site Starter kit
gridview
Asp.Net User
Re: InsertParameters element ?7/20/2006 10:57:17 PM

0/0

Thanks for your reply,

yes i was refering to ObjectDataSource,

Actually i am total beginner, i could not follow exactly what you explained me,

Could you please  explain little bit more.

And  i have a question about your reply : there is  AddBlogEntry  procedure in your code instead of InsertBlogEntry ?

 

 

jwadsworth:

If your referring to the ObjectDataSource here is an example:

<asp:ObjectDataSource ID="ObjectDataSourceBlogEntries" Runat="server"    
     TypeName
="BlogManager"    SelectMethod="GetBlogEntries" InsertMethod="AddBlogEntry">
      
<SelectParameters>
         
<asp:SessionParameter DefaultValue=""
            
Name="category"
            
Direction="input"
            
SessionField="blogcategory"
            
Type="string"
            
ConvertEmptyStringToNull="false" />
         
</SelectParameters>
      
<InsertParameters>
         
<asp:SessionParameter DefaultValue=""
            
Name="category"
            
Direction="Input"
            
SessionField="blogcategory"
            
Type="string"
            
ConvertEmptyStringToNull="false" />
      </InsertParameters>
</asp:ObjectDataSource>

Note that in this example I am setting a session variable in code that is used. The GetBlogEntries and InsertBlogEntry procedures must accept a value of type string. I have them both as optional values set to a blank string, such as:

 

Public Shared Function GetBlogEntries(Optional ByVal Category As String = "") As Generic.List(Of Blog)
   
Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("Personal").ConnectionString)

      Dim strSPROC As String = ""
      
If Category.Trim = "" Then
         
strSPROC = "blog_GetBlogEntries"
      
Else
         
strSPROC = "blog_GetBlogEntriesByCategory"
      
End If

      Using command As New SqlCommand(strSPROC, connection)
command.CommandType = CommandType.StoredProcedure
         
connection.Open()
         
If Category.Trim <> "" Then command.Parameters.Add(New SqlParameter("@Category", Category))
            
Dim list As New Generic.List(Of Blog)()
            
Using reader As SqlDataReader = command.ExecuteReader()
               
Do While (reader.Read())
                  
Dim temp As New Blog(CInt(reader("EntryID")), CStr(reader("Category")), CStr(reader("EntryTitle")), CStr(reader("EntryText")), CStr(reader("UserName")), CDate(reader("DateCreated")), CInt(reader("IsDeleted")), CInt(reader("CommentCount")))

                  list.Add(temp)
               

Loop
            
End Using
            
Return list
         
End Using
   
End Using
End Function
jwadsworth
Asp.Net User
Re: InsertParameters element ?7/21/2006 12:01:52 AM

0/0

Here is maybe a little simpler example. You would of course need to change the procedure name referenced as the InsertMethod. You would also need to add a value to be accepted in your procedure.

On your page you have the ObjectDataSource. You would specify the TypeName as the class that your procedure resides in. Then specify the procedure in the InsertMethod. Next, inside the <InsertParameters> tag you would declare the type of asp: parameter to user. In this case I chose a SessionParameter. There are 7 different types of parameters that you can use. Play with the intellisense to see the others. In the SessionParameter below, the SessionField property refers to the name of the session variable I have set elsewhere in code. The Name property refers to the name of the variable used in the Procedure such as MyFunction(Byval category As String), where category is the variable referred to in the Name property below.

<asp:ObjectDataSource ID="ObjectDataSourceBlogEntries" Runat="server"    
     TypeName
="BlogManager" 
InsertMethod="AddBlogEntry">
      <InsertParameters>
         
<asp:SessionParameter DefaultValue
=""
            
Name
="category"
            
Direction
="Input"
            
SessionField
="blogcategory"
            
Type
="string"
            
ConvertEmptyStringToNull="false"
/>
      </InsertParameters
>
</asp:ObjectDataSource>

Then you have your procedure that is referred to in the InsertMethod above.

Public Shared Function GetBlogEntries(Optional ByVal category As String = "") As Generic.List(Of Blog) 

 ' In here you would have code that uses the Category value passed in to Insert into the database.

End Function

 


Jeremy

Extended Personal Site Starter kit
gridview
Asp.Net User
Re: InsertParameters element ?7/21/2006 6:17:59 AM

0/0

Thanks for your reply.

I have few more questions.Please check the following if  my understanding is on right path or not.

Q 1. These are the 7 different parameters which you mentioned in your reply  ?

   Parameter

  QueryStringParameter

   ControParameter

   SessionParameter

   FormParameter

   CookieParameter

  ProfileParameter

 

Q 2    First you assigned    InsertMethod="AddBlogEntry"

 becasue  InsertMethod gets  the name of the method that the ObjectDataSource control invokes to insert data  ?

 

Q 3 You decalred SessionParameter inside <InsertParameter>

because  InsertParameter gets the parameters collection that contains the parameters that are used by the InsertMethod method i.e AddBlogEntry  ?

 

 

 

jwadsworth:

Here is maybe a little simpler example. You would of course need to change the procedure name referenced as the InsertMethod. You would also need to add a value to be accepted in your procedure.

On your page you have the ObjectDataSource. You would specify the TypeName as the class that your procedure resides in. Then specify the procedure in the InsertMethod. Next, inside the <InsertParameters> tag you would declare the type of asp: parameter to user. In this case I chose a SessionParameter. There are 7 different types of parameters that you can use. Play with the intellisense to see the others. In the SessionParameter below, the SessionField property refers to the name of the session variable I have set elsewhere in code. The Name property refers to the name of the variable used in the Procedure such as MyFunction(Byval category As String), where category is the variable referred to in the Name property below.

<asp:ObjectDataSource ID="ObjectDataSourceBlogEntries" Runat="server"    
     TypeName
="BlogManager" 
InsertMethod="AddBlogEntry">
      <InsertParameters>
         
<asp:SessionParameter DefaultValue
=""
            
Name
="category"
            
Direction
="Input"
            
SessionField
="blogcategory"
            
Type
="string"
            
ConvertEmptyStringToNull="false"
/>
      </InsertParameters
>
</asp:ObjectDataSource>

Then you have your procedure that is referred to in the InsertMethod above.

Public Shared Function GetBlogEntries(Optional ByVal category As String = "") As Generic.List(Of Blog) 

 ' In here you would have code that uses the Category value passed in to Insert into the database.

End Function

 

jwadsworth
Asp.Net User
Re: InsertParameters element ?7/21/2006 7:08:40 AM

0/0

Q1. Yes those are the seven differnt parameters

Q2. Yes.

Q3. Yes. In the case that you use the SessionParameter you would have a session variable set somewhere in code.

 


Jeremy

Extended Personal Site Starter kit
gridview
Asp.Net User
Re: InsertParameters element ?7/21/2006 12:20:39 PM

0/0

Thanks for your reply.

I have another question not related to previous post, i put this question in forum but could not get it, if possible please explain it to me .

Case:  I am talking about Personal Wesbite Starter , In Admin/Photo.aspx method,

there are  code lines:

<

asp:datalist runat="server" id="UploadList" repeatcolumns="1" repeatlayout="table" repeatdirection="horizontal" DataSourceID="ObjectDataSource2">

<itemtemplate>

<%# Container.DataItem %>

</itemtemplate>

</asp:datalist>

My question is What does <%# Container.DataItem %> does in the above lines  of code ?

jwadsworth
Asp.Net User
Re: InsertParameters element ?7/21/2006 4:48:24 PM

0/0

I'm not 100% sure about this but I think Container refers to the object or source that the DataList is bound to. DataItem refers to the item in the collection being bound.


Jeremy

Extended Personal Site Starter kit
gridview
Asp.Net User
Re: InsertParameters element ?7/22/2006 2:14:44 PM

0/0

Thanks for your reply.
9 Items, 1 Pages 1 |< << Go >> >|



Search This Site:


Meet Our Sponsors:



Other Resources:

Upload File Example ... - ng.asp-net-forum.visual_web_developer_2005_express - Web Programming Newsgroups SqlDataSource1.InsertParameters("Picture").DefaultValue = PictureInsert.FileName ... Element-IT Examples Source Viewer : ... equiv="Content-Type" content="text/html; ...
Name 'CreateUserWizardStep1' is not declared - newsgroup.asp-net-forum.general_asp-net-security - Web Programming ... Line 21: DataSource.InsertParameters.Add("UserId", UserGUID.ToString) ... authentication> element, set the loginUrl, defaultUrl, name ...
ObjectDataSource.InsertMethod Property (System.Web.UI.WebControls) Gets or sets the name of the method or function that the ObjectDataSource ... Next, the parameters that are listed in the InsertParameters element are added. ...
ASP.NET Reference InsertParameters ... InsertParameters> SelectCommand ... Gets or sets the horizontal or vertical position of the HTML caption element in a control. ...
Carl Zumbano foreach (Google.ResultElement element in result.resultElements) ... UrlSqlDataSource.InsertParameters["Link"].DefaultValue = element.URL.ToString ...
Connect to SQL Server using a SqlDataSource Control C# ... a connection string stored in the <connectionStrings> configuration element. ... <InsertParameters> <asp:Parameter Name="CategoryName" Type="String" ...
How to display all data by default in a GridView? - ASP.NET Forums <InsertParameters> </InsertParameters> </asp:ObjectDataSource> Many Thanks! ... "EmpIDColumn" type="xs:int" minOccurs="0" /> 91 <xs:element name="EmpName" msdata: ...
Index for Murach's ASP.NET 2.0 with C# 2005 AlternatingItemStyle element (data list), 395 ... InsertParameters element (SqlDataSource control), 402, 403. InsertParameters property (SqlDataSource control), 429 ...
Index for Murach's ASP.NET 3.5 with VB 2008 Border attribute (Table element), 196, 197. BorderColor attribute (calendar control), 242, 243 ... InsertParameters element (SqlDataSource control), 422, 423 ...
Office Live template tips | Darren's SharePoint and .Net blog Recently I've been heavily involved in writing Office Live site templates. ... InsertParameters elements will be configured with the internal guid of the list ...


 
All Times Are GMT