943,640 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 683
  • ASP.NET RSS
Apr 16th, 2009
0

Asp.net behind code not correct

Expand Post »
hi,
there, im coming up with codes to connect asp.net interface(Track) with asp.net interface(Clerk). i am not sure if my codes are correct. at the same time, i am not sure how to write codes to write the select statement which can connect asp.net interface with sql server. please help.


ASP.NET Syntax (Toggle Plain Text)
  1. <%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" %>
  2. <%@Import NameSpace="System.Data" %>
  3. <%@ Import Namespace="System.Data.SqlClient" %>
  4. <%@ Import Namespace="System.Configuration" %>
  5.  
  6.  
  7. <script runat="server">
  8.  
  9. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  10. Dim MyConnection As SqlConnection
  11. Dim MyCommand As SqlCommand
  12. Dim MyReader As SqlDataReader
  13.  
  14. MyConnection = New SqlConnection()
  15. MyConnection.ConnectionString = _
  16. ConfigurationManager.ConnectionStrings("ConnectionString2").ConnectionString
  17. Dim str As String = "insert into track(TrackingID,PickDATE,Consignment,Reference,Origin,Destination,Status,Destination,RecipientName) Values('" &TextBox1.Text& "','"&TextBox2&"','"&TextBox3.Text&"','" &TextBox4.Text& "','" &TextBox5.Text& "','" &TextBox6.Text& "','" &TextBox7.Text& "','" &TextBox8.Text& "');"
  18. Dim Command As SqlCommand = "Select TrackingID.Track from Clerk where (TrackingID.Track=TrackID.Clerk) "
  19.  
  20. MyCommand = New SqlCommand
  21. MyCommand.CommandText = "Select "
  22. MyCommand.CommandText = MyCommand.CommandText + "'"
  23.  
  24. MyCommand.CommandText = MyCommand.CommandText + "'"
  25.  
  26. MyCommand.CommandText = MyCommand.CommandText
  27. MyCommand.Connection = MyConnection
  28.  
  29. MyCommand.Connection.Open()
  30. MyReader = MyCommand.ExecuteReader()
  31.  
  32. MyCommand.Dispose()
  33. MyConnection.Dispose()
  34.  
  35.  
  36.  
  37.  
  38. End Sub
  39.  
  40. </script>
Last edited by Ezzaral; Apr 16th, 2009 at 11:14 pm. Reason: Added code tags. Learn to use them.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
chriscross86 is offline Offline
54 posts
since Feb 2009
Apr 17th, 2009
0

Re: Asp.net behind code not correct

where are you using this:

ASP.NET Syntax (Toggle Plain Text)
  1. Dim str As String = "insert into track(TrackingID,PickDATE,Consignment,Reference,Origin,Destination,Status,Destination,RecipientName) Values('" &TextBox1.Text& "','"&TextBox2&"','"&TextBox3.Text&"','" &TextBox4.Text& "','" &TextBox5.Text& "','" &TextBox6.Text& "','" &TextBox7.Text& "','" &TextBox8.Text& "');"
Reputation Points: 22
Solved Threads: 9
Junior Poster
ninjaimp is offline Offline
129 posts
since Apr 2008
Apr 20th, 2009
0

Re: Asp.net behind code not correct

im using this in the script section .before the body.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
chriscross86 is offline Offline
54 posts
since Feb 2009
Apr 20th, 2009
0

Re: Asp.net behind code not correct

can you show all your code, so i can see where your using the string?
Reputation Points: 22
Solved Threads: 9
Junior Poster
ninjaimp is offline Offline
129 posts
since Apr 2008
Apr 20th, 2009
0

Re: Asp.net behind code not correct

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" %>
<%@Import NameSpace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Configuration" %>


<script runat="server">

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Redirect("Clerk")

Dim MyConnection As SqlConnection
Dim MyCommand As SqlCommand
Dim MyReader As SqlDataReader

MyConnection = New SqlConnection()
MyConnection.ConnectionString = _
ConfigurationManager.ConnectionStrings("ConnectionString2").ConnectionString
Dim str As String = "insert into Track(TrackingID,PickDATE,Consignment,Reference,Origin,Destination,Status,Destination,RecipientName) Values('" &TextBox1.Text& "','" &TextBox2& "','" &TextBox3.Text& "','" &TextBox4.Text& "','" &TextBox5.Text& "','" &TextBox6.Text& "','" &TextBox7.Text& "','" &TextBox8.Text& "');"


MyCommand = New SqlCommand

MyCommand.CommandText = MyCommand.CommandText + "'"

MyCommand.CommandText = MyCommand.CommandText + "'"

MyCommand.CommandText = MyCommand.CommandText
MyCommand.Connection = MyConnection

MyCommand.Connection.Open()
MyReader = MyCommand.ExecuteReader()

MyCommand.Dispose()
MyConnection.Dispose()




End Sub




</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p>
<br />
</p>
<p>
</p>
<p>
&nbsp; TRACK MY SHIPMENT</p>
<p>
&nbsp;</p>
<p>
&nbsp;</p>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Tracking ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
</p>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" Text="TRACK" Width="96px" />
&nbsp;</p>
<p>
</p>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PICK UP
DATE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CONSIGNMENT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
REFERENCE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
ORIGIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DESTINATION&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
STATUS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
RECIPIENT NAME</p>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox2" runat="server" Height="42px" Width="93px"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox3" runat="server" Height="42px" Width="93px"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox4" runat="server" Height="42px" Width="93px"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox5" runat="server" Height="42px" Width="93px"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox6" runat="server" Height="42px" Width="93px"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox7" runat="server" Height="42px" Width="93px"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox8" runat="server" Height="42px" Width="93px"></asp:TextBox>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>

<aspqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
SelectCommand="Select TrackingID from [Clerk] where TrackingID=NationWideAccount"></aspqlDataSource>

<aspqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
SelectCommand="Select TrackID from [Clerk],[PickUpForm] where PickDATE=PickUp,Consignment=Consignment,Reference=TrackingID,Origin=Address,Destination=Location,Status=Status,RecipientName=RecipientName "></aspqlDataSource>
</asp:Content>
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
chriscross86 is offline Offline
54 posts
since Feb 2009
Apr 20th, 2009
0

Re: Asp.net behind code not correct

your creating this string:

ASP.NET Syntax (Toggle Plain Text)
  1.  
  2. Dim str As String = "insert into Track(TrackingID,PickDATE,Consignment,Reference,Origin,Destination,Status,Destination,RecipientName) Values('" &TextBox1.Text& "','" &TextBox2& "','" &TextBox3.Text& "','" &TextBox4.Text& "','" &TextBox5.Text& "','" &TextBox6.Text& "','" &TextBox7.Text& "','" &TextBox8.Text& "');"

doesnt appear to be used any where -

give something like this a try:

ASP.NET Syntax (Toggle Plain Text)
  1.  
  2. dim connectionstring = SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString2").ConnectionString)
  3.  
  4. Dim str As String = "insert into Track(TrackingID,PickDATE,Consignment,Reference,Origin,Destination,Status,Destination,RecipientName) Values('" &TextBox1.Text& "','" &TextBox2& "','" &TextBox3.Text& "','" &TextBox4.Text& "','" &TextBox5.Text& "','" &TextBox6.Text& "','" &TextBox7.Text& "','" &TextBox8.Text& "');"
  5.  
  6. Dim scomm As Sqlcommand(str,connectionstring)
  7.  
  8. Dim MyReader As SqlDataReader
  9.  
  10. scomm = scomm.ExecuteReader()
Reputation Points: 22
Solved Threads: 9
Junior Poster
ninjaimp is offline Offline
129 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: error in the programming code
Next Thread in ASP.NET Forum Timeline: how to create a dynamic dropdownlist?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC