Asp.net behind code not correct

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2009
Posts: 54
Reputation: chriscross86 is an unknown quantity at this point 
Solved Threads: 0
chriscross86 chriscross86 is offline Offline
Junior Poster in Training

Asp.net behind code not correct

 
0
  #1
Apr 16th, 2009
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.


  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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 114
Reputation: ninjaimp is an unknown quantity at this point 
Solved Threads: 6
ninjaimp ninjaimp is offline Offline
Junior Poster

Re: Asp.net behind code not correct

 
0
  #2
Apr 17th, 2009
where are you using this:

  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& "');"
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 54
Reputation: chriscross86 is an unknown quantity at this point 
Solved Threads: 0
chriscross86 chriscross86 is offline Offline
Junior Poster in Training

Re: Asp.net behind code not correct

 
0
  #3
Apr 20th, 2009
im using this in the script section .before the body.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 114
Reputation: ninjaimp is an unknown quantity at this point 
Solved Threads: 6
ninjaimp ninjaimp is offline Offline
Junior Poster

Re: Asp.net behind code not correct

 
0
  #4
Apr 20th, 2009
can you show all your code, so i can see where your using the string?
Please mark this post as 'Solved' if it has helped and fixed your issue.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 54
Reputation: chriscross86 is an unknown quantity at this point 
Solved Threads: 0
chriscross86 chriscross86 is offline Offline
Junior Poster in Training

Re: Asp.net behind code not correct

 
0
  #5
Apr 20th, 2009
<%@ 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>
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 114
Reputation: ninjaimp is an unknown quantity at this point 
Solved Threads: 6
ninjaimp ninjaimp is offline Offline
Junior Poster

Re: Asp.net behind code not correct

 
0
  #6
Apr 20th, 2009
your creating this string:

  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:

  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()
Please mark this post as 'Solved' if it has helped and fixed your issue.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC