13 Replies - 10123 Views - Last Post: 02 May 2009 - 10:53 AM Rate Topic: -----

#1 Hawkx1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-April 09

Insert data with ASP.NET VB code into a database

Posted 27 April 2009 - 08:58 PM

		Dim loop_count As Integer = 0
		Dim loop_count1 As Integer = 0
		Dim old_loan As Double
		Dim Overpay As Double = CDbl(txtOverpay.Text) + Payment
		Dim loan As Double = CDbl(txtAmount.Text)
		Dim loan1 As Double = loan
		Dim loan2 As Double = loan
		Dim total_interest As Double = 0
		Dim total_interest1 As Double = 0
		Dim total_interest2 As Double = 0
		Dim ytd_interest As Double = 0
		Dim ytd_Interest1 As Double = 0
		Dim Interest(MaxMonths), Interest1(MaxMonths), Interest2(MaxMonths), Principal(MaxMonths), Principal1(MaxMonths), _
		Principal2(MaxMonths), balance_due(MaxMonths), balance_due1(MaxMonths), balance_due2(MaxMonths), OverPayment(MaxMonths) As Double
		Dim NextMonth As Date

		For loopctr = 0 To (LoanTerm - 1)
			Interest(loopctr) = loan * MonthlyInterest
			Principal(loopctr) = Payment - Interest(loopctr)
			total_interest += Interest(loopctr)
			old_loan = loan
			loan = loan * (1.0 + MonthlyInterest) - Payment
			If (loan < 0) Then
				balance_due(loopctr) = 0.0
				Interest(loopctr) = old_loan * MonthlyInterest
				Principal(loopctr) = old_loan * (1.0 + MonthlyInterest) - Interest(loopctr)
			Else
				balance_due(loopctr) = loan
				If (balance_due(loopctr) < 0.01) Then
					balance_due(loopctr) = 0
				End If
			End If
			If balance_due(loopctr) > 0 Then
				loop_count += 1
			End If
			If chkOverpay.Checked = True Then
				If (loan1 > 0) Then
					Interest1(loopctr) = loan1 * MonthlyInterest
					Principal1(loopctr) = Overpay - Interest1(loopctr)
					total_interest1 += Interest1(loopctr)
					old_loan = loan1
					loan1 = loan1 * (1 + MonthlyInterest) - Overpay
					balance_due1(loopctr) = loan1
					loop_count1 += 1
				End If
				If (loan1 < 0) Then
					loan1 = 0
					balance_due1(loopctr) = 0
					Interest1(loopctr) = old_loan * MonthlyInterest
					Principal1(loopctr) = old_loan * (1 + MonthlyInterest) - Interest1(loopctr)
				End If
			End If
		Next
		If (chkDates.Checked = True) Then
			Overpay = CDbl(txtOverpay.Text) + Payment
			NextMonth = Date1
			For loop_count = 1 To LoanTerm
				ytd_interest += Interest(loop_count)
				'outputFile.Write(" " & loop_count & " " & NextMonth & " " & FormatCurrency(Interest(loop_count)) & " " & FormatCurrency(Principal(loop_count)) & " " & FormatCurrency(balance_due(loop_count)) & " " & FormatCurrency(ytd_interest))
				If (loop_count < loop_count1 And chkOverpay.Checked = True) Then
					ytd_Interest1 += Interest1(loop_count)
					'outputFile.Write(" " & FormatCurrency(Interest1(loop_count)) & "  " & FormatCurrency(Principal1(loop_count)) & "  " & FormatCurrency(balance_due1(loop_count)) & "  " & FormatCurrency(ytd_Interest1))
				End If
				NextMonth = DateAdd(DateInterval.Month, 1, NextMonth)
			Next
		Else ' No Date Needed
			For loop_count = 1 To LoanTerm
				ytd_interest += Interest(loop_count)
				'outputFile.Write(" " & loop_count & " " & FormatCurrency(Interest(loop_count)) & " " & FormatCurrency(Principal(loop_count)) & " " & FormatCurrency(balance_due(loop_count)) & " " & FormatCurrency(ytd_interest))
				If (loop_count < loop_count1 And chkOverpay.Checked = True) Then
					ytd_Interest1 += Interest1(loop_count)
					'outputFile.Write(" " & FormatCurrency(Interest1(loop_count)) & "  " & FormatCurrency(Principal1(loop_count)) & "  " & FormatCurrency(balance_due1(loop_count)) & "  " & FormatCurrency(ytd_Interest1))
				End If
			Next
		End If



I need help taking the values in the outputFile.Write statements (it was originally made in VB to write to a text file) and place them in a database. i am using Visual Studio 2008 to create this and yes it is for homework so I need to know quickly. This new project is an ASP.NET web site and therefore probably works differently than in straight VB. if you have questions please let me know via reply.

Is This A Good Question/Topic? 0
  • +

Replies To: Insert data with ASP.NET VB code into a database

#2 Daegan  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 67
  • Joined: 17-March 09

Re: Insert data with ASP.NET VB code into a database

Posted 28 April 2009 - 12:30 AM

Typically you'd use an ASP form, setup an SQL statement with the SELECT, UPDATE, DELETE, and INSERT parameters, point it to the correct table and database, and go from there.
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Insert data with ASP.NET VB code into a database

Posted 28 April 2009 - 03:55 AM

I would look into the SqlConnection and SqlCommand classes.
Was This Post Helpful? 0
  • +
  • -

#4 Hawkx1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-April 09

Re: Insert data with ASP.NET VB code into a database

Posted 28 April 2009 - 06:47 PM

View Posteclipsed4utoo, on 28 Apr, 2009 - 02:55 AM, said:

I would look into the SqlConnection and SqlCommand classes.

So I add an sqldatasource to the page connect it to the database and use the sqlcommand or sqlconnection because right now with an accessdatasource there's none of that?

This post has been edited by Hawkx1: 28 April 2009 - 06:48 PM

Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Insert data with ASP.NET VB code into a database

Posted 29 April 2009 - 03:26 AM

View PostHawkx1, on 28 Apr, 2009 - 08:47 PM, said:

View Posteclipsed4utoo, on 28 Apr, 2009 - 02:55 AM, said:

I would look into the SqlConnection and SqlCommand classes.

So I add an sqldatasource to the page connect it to the database and use the sqlcommand or sqlconnection because right now with an accessdatasource there's none of that?


You either use the SqlConnection and SqlCommand class, or you use the SqlDataSource. You don't use both.

Personally, I like using the SqlConnection and SqlCommand classes. I don't ever use the SqlDataSource because I feel that I have more control when I am writing the code.
Was This Post Helpful? 0
  • +
  • -

#6 Hawkx1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-April 09

Re: Insert data with ASP.NET VB code into a database

Posted 29 April 2009 - 05:52 PM

When i try to add a dim for sqlcommand or connection i only get these possible selections from Intellisense when i get as far as Dim (name) as new sqlc
Dim conn As New SqlCacheDependency
	  Dim conn As New SqlCacheDependencyAdmin


Is there some library I need to inherit since the only inherit i get is "Inherits System.Web.UI.Page"

P.S Would've added a screenshot but the reply page won't take it.

This post has been edited by Hawkx1: 29 April 2009 - 05:52 PM

Was This Post Helpful? 0
  • +
  • -

#7 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Insert data with ASP.NET VB code into a database

Posted 30 April 2009 - 04:02 AM

View PostHawkx1, on 29 Apr, 2009 - 07:52 PM, said:

When i try to add a dim for sqlcommand or connection i only get these possible selections from Intellisense when i get as far as Dim (name) as new sqlc
Dim conn As New SqlCacheDependency
	  Dim conn As New SqlCacheDependencyAdmin


Is there some library I need to inherit since the only inherit i get is "Inherits System.Web.UI.Page"

P.S Would've added a screenshot but the reply page won't take it.


you need to import..

Imports System.Data.SqlClient
Imports System.Data


Was This Post Helpful? 0
  • +
  • -

#8 Hawkx1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-April 09

Re: Insert data with ASP.NET VB code into a database

Posted 30 April 2009 - 06:34 AM

View Posteclipsed4utoo, on 30 Apr, 2009 - 03:02 AM, said:

View PostHawkx1, on 29 Apr, 2009 - 07:52 PM, said:

When i try to add a dim for sqlcommand or connection i only get these possible selections from Intellisense when i get as far as Dim (name) as new sqlc
Dim conn As New SqlCacheDependency
	  Dim conn As New SqlCacheDependencyAdmin


Is there some library I need to inherit since the only inherit i get is "Inherits System.Web.UI.Page"

P.S Would've added a screenshot but the reply page won't take it.


you need to import..

Imports System.Data.SqlClient
Imports System.Data



In my web site there is no import command there is only Implement also I need to find out where to place it.
Was This Post Helpful? 0
  • +
  • -

#9 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Insert data with ASP.NET VB code into a database

Posted 30 April 2009 - 09:13 AM

View PostHawkx1, on 30 Apr, 2009 - 08:34 AM, said:

View Posteclipsed4utoo, on 30 Apr, 2009 - 03:02 AM, said:

View PostHawkx1, on 29 Apr, 2009 - 07:52 PM, said:

When i try to add a dim for sqlcommand or connection i only get these possible selections from Intellisense when i get as far as Dim (name) as new sqlc
Dim conn As New SqlCacheDependency
	  Dim conn As New SqlCacheDependencyAdmin


Is there some library I need to inherit since the only inherit i get is "Inherits System.Web.UI.Page"

P.S Would've added a screenshot but the reply page won't take it.


you need to import..

Imports System.Data.SqlClient
Imports System.Data



In my web site there is no import command there is only Implement also I need to find out where to place it.


this is VB.Net, right?

at the very top of the code behind, you should see other "Imports" statements.
Was This Post Helpful? 0
  • +
  • -

#10 Hawkx1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-April 09

Re: Insert data with ASP.NET VB code into a database

Posted 30 April 2009 - 09:46 AM

Maybe I was unclear this is an ASP.NET Web Site that has VB code behind it there is an App_Code folder which now contains a database, a default.aspx, a default.aspx.vb and a web.config file.
Was This Post Helpful? 0
  • +
  • -

#11 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Insert data with ASP.NET VB code into a database

Posted 30 April 2009 - 12:41 PM

now open the default.aspx.vb file. at the very top, paste these two lines ABOVE EVERYTHING...

Imports System.Data.SqlClient
Imports System.Data


Was This Post Helpful? 1
  • +
  • -

#12 Hawkx1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-April 09

Re: Insert data with ASP.NET VB code into a database

Posted 30 April 2009 - 02:11 PM

Thank you now i need to figure out how to fashion the insert statement to accept the data since the sqlcommand and connection only show how to make it work for a select statement not an insert statement. Right now I just copied and pasted what a sqldatasource outputs as a insert statement.
Was This Post Helpful? 0
  • +
  • -

#13 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Insert data with ASP.NET VB code into a database

Posted 30 April 2009 - 03:07 PM

View PostHawkx1, on 30 Apr, 2009 - 04:11 PM, said:

Thank you now i need to figure out how to fashion the insert statement to accept the data since the sqlcommand and connection only show how to make it work for a select statement not an insert statement. Right now I just copied and pasted what a sqldatasource outputs as a insert statement.


the SqlCommand object can run a standard query.

SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Insert INTO .....";
cmd.Connection = yourConnectionInstance;

int rowsEffected = cmd.ExecuteNonQuery();


This post has been edited by eclipsed4utoo: 30 April 2009 - 03:08 PM

Was This Post Helpful? 0
  • +
  • -

#14 Hawkx1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-April 09

Re: Insert data with ASP.NET VB code into a database

Posted 02 May 2009 - 10:53 AM

All problems have been fixed that's to all who responded now how do i close this topic.

This post has been edited by Hawkx1: 02 May 2009 - 10:53 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1