Wednesday, March 21, 2012

Need Comments

Can someone please give me comments to every lines to this code: (I think I know, but Iam not sure):

Dim ConnString As String = ConfigurationManager.ConnectionStrings("Connectionstring").ConnectionString

Dim strSQL As String = ("INSERT INTO Tabel3( City) VALUES ( @.City )")

Dim Conn As New SqlConnection(ConnString)

Dim Command As New SqlCommand("", Conn)

Command.CommandText = strSQL

Conn.Open()

Command.ExecuteNonQuery()

Conn.Close()

By the way, I got a question about the DetailsView in ASP.NET 2.0 (none answearing me at forums.asp.net .....:

I want to hide a <TemplateField> in Edit-mode of the Detailsview....Ive got a <hr /> in the <TemplateField> and I dont want to display it in Edit-mode...

I found this link: http://www.asp101.com/articles/sample_chapters/sitepoint_byoaspnet/chapter4.asp

Scroll down and you will see: HTMLGenericControl

There they use a <span> to change the text to another...Couldnt I use this to my issue? The different is that I have my span in a TemplateField :

<asp:TemplateField InsertVisible="false">
<ItemTemplate>
<span id="hr" runat="server"><hr /></span>
</ItemTemplate>
<HeaderTemplate><hr /></HeaderTemplate>
</asp:TemplateField>

Sub Detailsview_ModeChanged(...........)

If DetailsView1.CurrentMode = DetailsViewMode.EditThen

CType(DetailsView1.FindControl("hr"), HtmlGenericControl).InnerHtml = (" ")

End if

End Sub

I done get it to work...so Iam very appreciate for all help I can get....

Hi, here's the comments:

'Get the database connection string from the configuration
Dim ConnString As String = ConfigurationManager.ConnectionStrings("Connectionstring").ConnectionString
'SQL command to execute
Dim strSQL As String = ("INSERT INTO Tabel3( City) VALUES ( @.City )")
'Create new db connection
Dim Conn As New SqlConnection(ConnString)
'Create new command for an empty query (it would be better pass strSQL as the first param)
Dim Command As New SqlCommand("", Conn)
'Replace the empty sql query from above to the sql command we want to execute
Command.CommandText = strSQL
'Missing: The value of the @.City parameter must be set
'Connect to DB
Conn.Open()
'Execute the query
Command.ExecuteNonQuery()
'Close connection to db
Conn.Close()

Charles

|||

OK...Thank you for your commments!

But what do you mean with " It would be better pass strSQL as the first param"?

Do you mean like this: Dim Command As New SqlCommand(strSQL, Conn) ? and why would that be better?

And if I replace "" with strSQL then the comments will be like this instead?

'Create new command for an SQL query (Or what ?)
Dim Command As New SqlCommand("", Conn)
'Replace the sql query from above to the sql command we want to execute
Command.CommandText = strSQL

Here is the code that I forgott (can you please give comments here too?):

Dim City As New SqlParameter("@.City", DbType.String)

City.Value = Context.Server.HtmlEncode(tboxCity.Text)

Command.Parameters.Add(City)


|||

' Creating the City parameter as type of String

Dim City As New SqlParameter("@.City", DbType.String)

' Encoding the tboxCity.Text & assign to city.Value

City.Value = Context.Server.HtmlEncode(tboxCity.Text)

' Finally Add the City Paramerter to the Command Object

Command.Parameters.Add(City)


No comments:

Post a Comment