?
Solved

text files

Posted on 2012-09-03
5
Medium Priority
?
508 Views
Last Modified: 2012-09-07
hey guys i have a text file on my sever

path:
album-maker/payment-folder/orderID.txt

now i need c# code to read the text file in a stream where i can get the values and set the values.

here my txt file

FIRST_NAME  = Mike
MIDDLE_NAME  = Johnson
LAST_NAME  = Kofman
CUSTOMER_ID =  14112
PRODUCT_DETAILS = MP_A4 Portrait
PRICE_LEFT_DECIMAL_POINT = 1189
PRICE_RIGHT_DECIMAL_POINT =39
DATE_TIME = 19145504122008
STREET =157th St.
DISTRICT = NY
CITY =New York
ZIP = 75443
STATE = NY
COUNTRY = America 
PHONE =  054533526
CELLULAR = 054533526
EMAIL = Kofman_Mike@hotmail.com
ATTEMPT_TO_UPLOAD =0
COVER_MATERIAL = Dark_Cover
COVER_COLOR = Gray
PAGE_COUNT = 40
COPIES = 1
COMMENT = 
FINISHING = 
COLOR_CORRECT = 0
IMAGE_COUNT = 7
CUSTOMER_TITLE = Mr.
CUSTOMER_BIRTHDATE = 00000023111972
USED_PRICING_FORMAT = 1
DECIMAL_SEPARATOR = .
BASIC_PAGES_PRICE = 454.00
ADDITIONAL_PAGES_PRICE = 155.00
ALBUM_BLOCK_PRICE = 564.00
COVER_PRICE = 200.00
COLOR_CORRECTION_PRICE = .00
FINISHING_PRICE = .00
ALBUM_PRICE = 1074.00
CD_PRICE = .00
ORDER_PRICE = 1074.00
TAX_NAME_1 = VAT
TAX_VALUE_1 = 107.40
TAX_NAME_2 = Shipment Tax
TAX_VALUE_2 = 2.99
ORDER_PRICE_INCLUDING_TAXES =1184.39
SHIPMENT_PRICE = 5.00
TOTAL_PRICE = 1189.39
DISCOUNT = .00
PAYED_AMOUNT = .00

Open in new window


please help
0
Comment
Question by:JCWEBHOST
  • 4
5 Comments
 
LVL 19

Expert Comment

by:Rimvis
ID: 38362770
Hi  JCWEBHOST,

This might be useful to you:

Simple way to read and write name value text file
http://stackoverflow.com/questions/3781706/simple-way-to-read-and-write-name-value-text-file
0
 
LVL 26

Accepted Solution

by:
Alan Warren earned 2000 total points
ID: 38363230
Hi
I was about to post a response to the last thread, but then it got deleted, hmmm.

I got this far with the last question titled "text files in asp" before it disappeared ...
<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  Sub Page_Load(sender As Object, e As EventArgs)
    
    
    Dim strTemp As String = ""
    Dim FIRST_NAME As String = ""
    Dim MIDDLE_NAME As String = ""
    Dim LAST_NAME As String = ""
    Dim PRODUCT_DETAILS As String = ""
    Dim PRICE_LEFT_DECIMAL_POINT As String = ""
    Dim PRICE_RIGHT_DECIMAL_POINT As String = ""
    Dim DATE_TIME As String = ""
    Dim STREET As String = ""
    Dim DISTRICT As String = ""
    Dim CITY As String = ""
    Dim ZIP As String = ""
    Dim STATE As String = ""
    Dim COUNTRY As String = ""
    Dim PHONE As String = ""
    Dim CELLULAR As String = ""
    Dim EMAIL As String = ""
    Dim COVER_MATERIAL As String = ""
    Dim ATTEMPT_TO_UPLOAD As String = ""
    Dim COVER_COLOR As String = ""
    Dim PAGE_COUNT As String = ""
    Dim COPIES As String = ""
    Dim COMMENT As String = ""
    Dim FINISHING As String = ""
    Dim COLOR_CORRECT As String = ""
    Dim IMAGE_COUNT As String = ""
    Dim CUSTOMER_ID As String = ""
    Dim CUSTOMER_TITLE As String = ""
    Dim CUSTOMER_BIRTHDATE As String = ""
    Dim USED_PRICING_FORMAT As String = ""
    Dim DECIMAL_SEPARATOR As String = ""
    Dim BASIC_PAGES_PRICE As String = ""
    Dim ADDITIONAL_PAGES_PRICE As String = ""
    Dim ALBUM_BLOCK_PRICE As String = ""
    Dim COVER_PRICE As String = ""
    Dim COLOR_CORRECTION_PRICE As String = ""
    Dim FINISHING_PRICE As String = ""
    Dim ALBUM_PRICE As String = ""
    Dim CD_PRICE As String = ""
    Dim ORDER_PRICE As String = ""
    Dim TAX_NAME_1 As String = ""
    Dim TAX_VALUE_1 As String = ""
    Dim TAX_NAME_2 As String = ""
    Dim TAX_VALUE_2 As String = ""
    Dim ORDER_PRICE_INCLUDING_TAXES As String = ""
    Dim SHIPMENT_PRICE As String = ""
    Dim TOTAL_PRICE As String = ""
    Dim DISCOUNT As String = ""
    Dim PAYED_AMOUNT As String = ""

    Dim myVarsArray As String() = {"FIRST_NAME", "MIDDLE_NAME", "LAST_NAME", "PRODUCT_DETAILS", "PRICE_LEFT_DECIMAL_POINT", "PRICE_RIGHT_DECIMAL_POINT", "DATE_TIME", "STREET", "DISTRICT", "CITY", "ZIP", "STATE", "COUNTRY", "PHONE", "CELLULAR", "EMAIL", "COVER_MATERIAL", "ATTEMPT_TO_UPLOAD", "COVER_COLOR", "PAGE_COUNT", "COPIES", "COMMENT", "FINISHING", "COLOR_CORRECT", "IMAGE_COUNT", "CUSTOMER_ID", "CUSTOMER_TITLE", "CUSTOMER_BIRTHDATE", "USED_PRICING_FORMAT", "DECIMAL_SEPARATOR", "BASIC_PAGES_PRICE", "ADDITIONAL_PAGES_PRICE", "ALBUM_BLOCK_PRICE", "COVER_PRICE", "COLOR_CORRECTION_PRICE", "FINISHING_PRICE", "ALBUM_PRICE", "CD_PRICE", "ORDER_PRICE", "TAX_NAME_1", "TAX_VALUE_1", "TAX_NAME_2", "TAX_VALUE_2", "ORDER_PRICE_INCLUDING_TAXES", "SHIPMENT_PRICE", "TOTAL_PRICE", "DISCOUNT", "PAYED_AMOUNT"}
    
    'Open a file for reading
    Dim FILENAME As String = Server.MapPath("~/the-files-folder/TextFile.txt")

    'Get a StreamReader class that can be used to read the file
    Dim objStreamReader As StreamReader
    objStreamReader = File.OpenText(FILENAME)

    'Now, read the entire file into a string
    Dim contents As String = "" 'objStreamReader.ReadToEnd()
    Dim line As String = ""
    While Not objStreamReader.EndOfStream
      line = objStreamReader.ReadLine()
      
      ' sanitise the doublespaces and equals operators
      line = line.Replace("  = ", " = ")
      line = line.Replace(" =  ", " = ")
      line = line.Replace(" =", " = ")
      line = line.Replace("  ", " ")
      
      ' Populate our local variables
      For i = 0 To myVarsArray.Length - 1
        If line.Contains(myVarsArray(i) & " = ") Then
          Select Case myVarsArray(i)
            Case Is = "FIRST_NAME"
              FIRST_NAME = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & FIRST_NAME & "<br />"
            Case Is = "MIDDLE_NAME"
              MIDDLE_NAME = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & MIDDLE_NAME & "<br />"
            Case Is = "LAST_NAME"
              LAST_NAME = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & LAST_NAME & "<br />"
            Case Is = "PRODUCT_DETAILS"
              PRODUCT_DETAILS = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & PRODUCT_DETAILS & "<br />"
            Case Is = "PRICE_LEFT_DECIMAL_POINT"
              PRICE_LEFT_DECIMAL_POINT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & PRICE_LEFT_DECIMAL_POINT & "<br />"
            Case Is = "PRICE_RIGHT_DECIMAL_POINT"
              PRICE_RIGHT_DECIMAL_POINT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & PRICE_RIGHT_DECIMAL_POINT & "<br />"
            Case Is = "DATE_TIME"
              DATE_TIME = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & DATE_TIME & "<br />"
            Case Is = "STREET"
              STREET = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & STREET & "<br />"
            Case Is = "DISTRICT"
              DISTRICT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & DISTRICT & "<br />"
            Case Is = "CITY"
              CITY = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & CITY & "<br />"
            Case Is = "ZIP"
              ZIP = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & ZIP & "<br />"
            Case Is = "STATE"
              STATE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & STATE & "<br />"
            Case Is = "COUNTRY"
              COUNTRY = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COUNTRY & "<br />"
            Case Is = "PHONE"
              PHONE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & PHONE & "<br />"
            Case Is = "CELLULAR"
              CELLULAR = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & CELLULAR & "<br />"
            Case Is = "EMAIL"
              EMAIL = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & EMAIL & "<br />"
            Case Is = "COVER_MATERIAL"
              COVER_MATERIAL = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COVER_MATERIAL & "<br />"
            Case Is = "ATTEMPT_TO_UPLOAD"
              ATTEMPT_TO_UPLOAD = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & ATTEMPT_TO_UPLOAD & "<br />"
            Case Is = "COVER_COLOR"
              COVER_COLOR = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COVER_COLOR & "<br />"
            Case Is = "PAGE_COUNT"
              PAGE_COUNT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & PAGE_COUNT & "<br />"
            Case Is = "COPIES"
              COPIES = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COPIES & "<br />"
            Case Is = "COMMENT"
              COMMENT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COMMENT & "<br />"
            Case Is = "FINISHING"
              FINISHING = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & FINISHING & "<br />"
            Case Is = "COLOR_CORRECT"
              COLOR_CORRECT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COLOR_CORRECT & "<br />"
            Case Is = "IMAGE_COUNT"
              IMAGE_COUNT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & IMAGE_COUNT & "<br />"
            Case Is = "CUSTOMER_ID"
              CUSTOMER_ID = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & CUSTOMER_ID & "<br />"
            Case Is = "CUSTOMER_TITLE"
              CUSTOMER_TITLE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & CUSTOMER_TITLE & "<br />"
            Case Is = "CUSTOMER_BIRTHDATE"
              CUSTOMER_BIRTHDATE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & CUSTOMER_BIRTHDATE & "<br />"
            Case Is = "USED_PRICING_FORMAT"
              USED_PRICING_FORMAT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & USED_PRICING_FORMAT & "<br />"
            Case Is = "DECIMAL_SEPARATOR"
              DECIMAL_SEPARATOR = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & DECIMAL_SEPARATOR & "<br />"
            Case Is = "BASIC_PAGES_PRICE"
              BASIC_PAGES_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & BASIC_PAGES_PRICE & "<br />"
            Case Is = "ADDITIONAL_PAGES_PRICE"
              ADDITIONAL_PAGES_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & ADDITIONAL_PAGES_PRICE & "<br />"
            Case Is = "ALBUM_BLOCK_PRICE"
              ALBUM_BLOCK_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & ALBUM_BLOCK_PRICE & "<br />"
            Case Is = "COVER_PRICE"
              COVER_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COVER_PRICE & "<br />"
            Case Is = "COLOR_CORRECTION_PRICE"
              COLOR_CORRECTION_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COLOR_CORRECTION_PRICE & "<br />"
            Case Is = "FINISHING_PRICE"
              FINISHING_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & FINISHING_PRICE & "<br />"
            Case Is = "ALBUM_PRICE"
              ALBUM_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & ALBUM_PRICE & "<br />"
            Case Is = "CD_PRICE"
              CD_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & CD_PRICE & "<br />"
            Case Is = "ORDER_PRICE"
              ORDER_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & ORDER_PRICE & "<br />"
            Case Is = "TAX_NAME_1"
              TAX_NAME_1 = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & TAX_NAME_1 & "<br />"
            Case Is = "TAX_VALUE_1"
              TAX_VALUE_1 = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & TAX_VALUE_1 & "<br />"
            Case Is = "TAX_NAME_2"
              TAX_NAME_2 = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & TAX_NAME_2 & "<br />"
            Case Is = "TAX_VALUE_2"
              TAX_VALUE_2 = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & TAX_VALUE_2 & "<br />"
            Case Is = "ORDER_PRICE_INCLUDING_TAXES"
              ORDER_PRICE_INCLUDING_TAXES = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & ORDER_PRICE_INCLUDING_TAXES & "<br />"
            Case Is = "SHIPMENT_PRICE"
              SHIPMENT_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & SHIPMENT_PRICE & "<br />"
            Case Is = "TOTAL_PRICE"
              TOTAL_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & TOTAL_PRICE & "<br />"
            Case Is = "DISCOUNT"
              DISCOUNT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & DISCOUNT & "<br />"
            Case Is = "PAYED_AMOUNT"
              PAYED_AMOUNT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & PAYED_AMOUNT & "<br />"
            Case Else
              ' do nothing
          End Select
        End If
        
      Next
      
    End While
    
    ' Write our sanitised string back to the page, so we can verify against the source file that we parsed it correctly
    lblSanitisedOutput.Text = strTemp
    
    objStreamReader.Close()
    
    ' Next step, put the local variables into a database catalog, 
    ' but maybe we should attempt to parse the rows into correct data types expected by the db first. 
    ' for that we would need some table schema, field names, types, sizes etc...
  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <b>Sanitised Output, which we now have in local variables.</b><br />
      <asp:label runat="server" id="lblSanitisedOutput" Font-Name="Verdana" />
    </div>
    </form>
</body>
</html>

Open in new window


C# Version
  public void Page_Load(object sender, EventArgs e)
  {


	string strTemp = "";
	string FIRST_NAME = "";
	string MIDDLE_NAME = "";
	string LAST_NAME = "";
	string PRODUCT_DETAILS = "";
	string PRICE_LEFT_DECIMAL_POINT = "";
	string PRICE_RIGHT_DECIMAL_POINT = "";
	string DATE_TIME = "";
	string STREET = "";
	string DISTRICT = "";
	string CITY = "";
	string ZIP = "";
	string STATE = "";
	string COUNTRY = "";
	string PHONE = "";
	string CELLULAR = "";
	string EMAIL = "";
	string COVER_MATERIAL = "";
	string ATTEMPT_TO_UPLOAD = "";
	string COVER_COLOR = "";
	string PAGE_COUNT = "";
	string COPIES = "";
	string COMMENT = "";
	string FINISHING = "";
	string COLOR_CORRECT = "";
	string IMAGE_COUNT = "";
	string CUSTOMER_ID = "";
	string CUSTOMER_TITLE = "";
	string CUSTOMER_BIRTHDATE = "";
	string USED_PRICING_FORMAT = "";
	string DECIMAL_SEPARATOR = "";
	string BASIC_PAGES_PRICE = "";
	string ADDITIONAL_PAGES_PRICE = "";
	string ALBUM_BLOCK_PRICE = "";
	string COVER_PRICE = "";
	string COLOR_CORRECTION_PRICE = "";
	string FINISHING_PRICE = "";
	string ALBUM_PRICE = "";
	string CD_PRICE = "";
	string ORDER_PRICE = "";
	string TAX_NAME_1 = "";
	string TAX_VALUE_1 = "";
	string TAX_NAME_2 = "";
	string TAX_VALUE_2 = "";
	string ORDER_PRICE_INCLUDING_TAXES = "";
	string SHIPMENT_PRICE = "";
	string TOTAL_PRICE = "";
	string DISCOUNT = "";
	string PAYED_AMOUNT = "";

	string[] myVarsArray = {"FIRST_NAME", "MIDDLE_NAME", "LAST_NAME", "PRODUCT_DETAILS", "PRICE_LEFT_DECIMAL_POINT", "PRICE_RIGHT_DECIMAL_POINT", "DATE_TIME", "STREET", "DISTRICT", "CITY", "ZIP", "STATE", "COUNTRY", "PHONE", "CELLULAR", "EMAIL", "COVER_MATERIAL", "ATTEMPT_TO_UPLOAD", "COVER_COLOR", "PAGE_COUNT", "COPIES", "COMMENT", "FINISHING", "COLOR_CORRECT", "IMAGE_COUNT", "CUSTOMER_ID", "CUSTOMER_TITLE", "CUSTOMER_BIRTHDATE", "USED_PRICING_FORMAT", "DECIMAL_SEPARATOR", "BASIC_PAGES_PRICE", "ADDITIONAL_PAGES_PRICE", "ALBUM_BLOCK_PRICE", "COVER_PRICE", "COLOR_CORRECTION_PRICE", "FINISHING_PRICE", "ALBUM_PRICE", "CD_PRICE", "ORDER_PRICE", "TAX_NAME_1", "TAX_VALUE_1", "TAX_NAME_2", "TAX_VALUE_2", "ORDER_PRICE_INCLUDING_TAXES", "SHIPMENT_PRICE", "TOTAL_PRICE", "DISCOUNT", "PAYED_AMOUNT"};

	//Open a file for reading
	string FILENAME = Server.MapPath("~/the-files-folder/TextFile.txt");

	//Get a StreamReader class that can be used to read the file
	StreamReader objStreamReader = null;
	objStreamReader = File.OpenText(FILENAME);

	//Now, read the entire file into a string
	string contents = ""; //objStreamReader.ReadToEnd()
	string line = "";
	while (!objStreamReader.EndOfStream)
	{
	  line = objStreamReader.ReadLine();

	  // sanitise the doublespaces and equals operators
	  line = line.Replace("  = ", " = ");
	  line = line.Replace(" =  ", " = ");
	  line = line.Replace(" =", " = ");
	  line = line.Replace("  ", " ");

	  // Populate our local variables
	  for (var i = 0; i < myVarsArray.Length; i++)
	  {
		if (line.Contains(myVarsArray(i) + " = "))
		{
		  switch (myVarsArray(i))
		  {
			case "FIRST_NAME":
			  FIRST_NAME = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + FIRST_NAME + "<br />";
			  break;
			case "MIDDLE_NAME":
			  MIDDLE_NAME = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + MIDDLE_NAME + "<br />";
			  break;
			case "LAST_NAME":
			  LAST_NAME = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + LAST_NAME + "<br />";
			  break;
			case "PRODUCT_DETAILS":
			  PRODUCT_DETAILS = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + PRODUCT_DETAILS + "<br />";
			  break;
			case "PRICE_LEFT_DECIMAL_POINT":
			  PRICE_LEFT_DECIMAL_POINT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + PRICE_LEFT_DECIMAL_POINT + "<br />";
			  break;
			case "PRICE_RIGHT_DECIMAL_POINT":
			  PRICE_RIGHT_DECIMAL_POINT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + PRICE_RIGHT_DECIMAL_POINT + "<br />";
			  break;
			case "DATE_TIME":
			  DATE_TIME = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + DATE_TIME + "<br />";
			  break;
			case "STREET":
			  STREET = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + STREET + "<br />";
			  break;
			case "DISTRICT":
			  DISTRICT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + DISTRICT + "<br />";
			  break;
			case "CITY":
			  CITY = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + CITY + "<br />";
			  break;
			case "ZIP":
			  ZIP = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + ZIP + "<br />";
			  break;
			case "STATE":
			  STATE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + STATE + "<br />";
			  break;
			case "COUNTRY":
			  COUNTRY = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COUNTRY + "<br />";
			  break;
			case "PHONE":
			  PHONE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + PHONE + "<br />";
			  break;
			case "CELLULAR":
			  CELLULAR = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + CELLULAR + "<br />";
			  break;
			case "EMAIL":
			  EMAIL = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + EMAIL + "<br />";
			  break;
			case "COVER_MATERIAL":
			  COVER_MATERIAL = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COVER_MATERIAL + "<br />";
			  break;
			case "ATTEMPT_TO_UPLOAD":
			  ATTEMPT_TO_UPLOAD = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + ATTEMPT_TO_UPLOAD + "<br />";
			  break;
			case "COVER_COLOR":
			  COVER_COLOR = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COVER_COLOR + "<br />";
			  break;
			case "PAGE_COUNT":
			  PAGE_COUNT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + PAGE_COUNT + "<br />";
			  break;
			case "COPIES":
			  COPIES = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COPIES + "<br />";
			  break;
			case "COMMENT":
			  COMMENT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COMMENT + "<br />";
			  break;
			case "FINISHING":
			  FINISHING = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + FINISHING + "<br />";
			  break;
			case "COLOR_CORRECT":
			  COLOR_CORRECT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COLOR_CORRECT + "<br />";
			  break;
			case "IMAGE_COUNT":
			  IMAGE_COUNT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + IMAGE_COUNT + "<br />";
			  break;
			case "CUSTOMER_ID":
			  CUSTOMER_ID = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + CUSTOMER_ID + "<br />";
			  break;
			case "CUSTOMER_TITLE":
			  CUSTOMER_TITLE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + CUSTOMER_TITLE + "<br />";
			  break;
			case "CUSTOMER_BIRTHDATE":
			  CUSTOMER_BIRTHDATE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + CUSTOMER_BIRTHDATE + "<br />";
			  break;
			case "USED_PRICING_FORMAT":
			  USED_PRICING_FORMAT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + USED_PRICING_FORMAT + "<br />";
			  break;
			case "DECIMAL_SEPARATOR":
			  DECIMAL_SEPARATOR = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + DECIMAL_SEPARATOR + "<br />";
			  break;
			case "BASIC_PAGES_PRICE":
			  BASIC_PAGES_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + BASIC_PAGES_PRICE + "<br />";
			  break;
			case "ADDITIONAL_PAGES_PRICE":
			  ADDITIONAL_PAGES_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + ADDITIONAL_PAGES_PRICE + "<br />";
			  break;
			case "ALBUM_BLOCK_PRICE":
			  ALBUM_BLOCK_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + ALBUM_BLOCK_PRICE + "<br />";
			  break;
			case "COVER_PRICE":
			  COVER_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COVER_PRICE + "<br />";
			  break;
			case "COLOR_CORRECTION_PRICE":
			  COLOR_CORRECTION_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COLOR_CORRECTION_PRICE + "<br />";
			  break;
			case "FINISHING_PRICE":
			  FINISHING_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + FINISHING_PRICE + "<br />";
			  break;
			case "ALBUM_PRICE":
			  ALBUM_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + ALBUM_PRICE + "<br />";
			  break;
			case "CD_PRICE":
			  CD_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + CD_PRICE + "<br />";
			  break;
			case "ORDER_PRICE":
			  ORDER_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + ORDER_PRICE + "<br />";
			  break;
			case "TAX_NAME_1":
			  TAX_NAME_1 = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + TAX_NAME_1 + "<br />";
			  break;
			case "TAX_VALUE_1":
			  TAX_VALUE_1 = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + TAX_VALUE_1 + "<br />";
			  break;
			case "TAX_NAME_2":
			  TAX_NAME_2 = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + TAX_NAME_2 + "<br />";
			  break;
			case "TAX_VALUE_2":
			  TAX_VALUE_2 = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + TAX_VALUE_2 + "<br />";
			  break;
			case "ORDER_PRICE_INCLUDING_TAXES":
			  ORDER_PRICE_INCLUDING_TAXES = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + ORDER_PRICE_INCLUDING_TAXES + "<br />";
			  break;
			case "SHIPMENT_PRICE":
			  SHIPMENT_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + SHIPMENT_PRICE + "<br />";
			  break;
			case "TOTAL_PRICE":
			  TOTAL_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + TOTAL_PRICE + "<br />";
			  break;
			case "DISCOUNT":
			  DISCOUNT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + DISCOUNT + "<br />";
			  break;
			case "PAYED_AMOUNT":
			  PAYED_AMOUNT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + PAYED_AMOUNT + "<br />";
			  break;
			default:
			  // do nothing
			break;
		  }
		}

	  }

	}
    
    ' Write our sanitised string back to the page, so we can verify against the source file that we parsed it correctly
    lblSanitisedOutput.Text = strTemp
    
    objStreamReader.Close()
    
    ' Next step, put the local variables into a database catalog, 
    ' but maybe we should attempt to parse the rows into correct data types expected by the db first. 
    ' for that we would need some table schema, field names, types, sizes etc...
  End Sub

Open in new window

0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38366093
Hi JCWEBHOST,
if you want to take this further, will need some schema for the destination table/tables, so we can convert the values from the input file to the db expected types and sizes.

Respectfully yours,
Alan
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38366098
Re:
That huge code is really not necessary, an array and a for loop would reduce that to 20 lines or less.
Sure it's doable, that was first draft; but, Me too ";0)
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38366265
Anyhow, moving on ...

We will need a table to put the parsed variable data into.

USE [yourdb]
GO

/****** Object:  Table [dbo].[Table_3]    Script Date: 09/05/2012 08:17:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Table_3](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[FIRST_NAME] [varchar](50) NULL,
	[MIDDLE_NAME] [varchar](50) NULL,
	[LAST_NAME] [varchar](50) NULL,
	[PRODUCT_DETAILS] [varchar](50) NULL,
	[PRICE_LEFT_DECIMAL_POINT] [varchar](50) NULL,
	[PRICE_RIGHT_DECIMAL_POINT] [varchar](50) NULL,
	[DATE_TIME] [varchar](50) NULL,
	[STREET] [varchar](50) NULL,
	[DISTRICT] [varchar](50) NULL,
	[CITY] [varchar](50) NULL,
	[ZIP] [varchar](50) NULL,
	[STATE] [varchar](50) NULL,
	[COUNTRY] [varchar](50) NULL,
	[PHONE] [varchar](50) NULL,
	[CELLULAR] [varchar](50) NULL,
	[EMAIL] [varchar](50) NULL,
	[COVER_MATERIAL] [varchar](50) NULL,
	[ATTEMPT_TO_UPLOAD] [varchar](50) NULL,
	[COVER_COLOR] [varchar](50) NULL,
	[PAGE_COUNT] [varchar](50) NULL,
	[COPIES] [varchar](50) NULL,
	[COMMENT] [varchar](50) NULL,
	[FINISHING] [varchar](50) NULL,
	[COLOR_CORRECT] [varchar](50) NULL,
	[IMAGE_COUNT] [varchar](50) NULL,
	[CUSTOMER_ID] [varchar](50) NULL,
	[CUSTOMER_TITLE] [varchar](50) NULL,
	[CUSTOMER_BIRTHDATE] [varchar](50) NULL,
	[USED_PRICING_FORMAT] [varchar](50) NULL,
	[DECIMAL_SEPARATOR] [varchar](50) NULL,
	[BASIC_PAGES_PRICE] [varchar](50) NULL,
	[ADDITIONAL_PAGES_PRICE] [varchar](50) NULL,
	[ALBUM_BLOCK_PRICE] [varchar](50) NULL,
	[COVER_PRICE] [varchar](50) NULL,
	[COLOR_CORRECTION_PRICE] [varchar](50) NULL,
	[FINISHING_PRICE] [varchar](50) NULL,
	[ALBUM_PRICE] [varchar](50) NULL,
	[CD_PRICE] [varchar](50) NULL,
	[ORDER_PRICE] [varchar](50) NULL,
	[TAX_NAME_1] [varchar](50) NULL,
	[TAX_VALUE_1] [varchar](50) NULL,
	[TAX_NAME_2] [varchar](50) NULL,
	[TAX_VALUE_2] [varchar](50) NULL,
	[ORDER_PRICE_INCLUDING_TAXES] [varchar](50) NULL,
	[SHIPMENT_PRICE] [varchar](50) NULL,
	[TOTAL_PRICE] [varchar](50) NULL,
	[DISCOUNT] [varchar](50) NULL,
	[PAYED_AMOUNT] [varchar](50) NULL,
 CONSTRAINT [PK_Table_3] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

Open in new window

And a stored procedure to handle inserting or updating:
USE [yourdb]
GO
/****** Object:  StoredProcedure [dbo].[Table_3_Ins_Or_Upd]    Script Date: 09/05/2012 07:44:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[Table_3_Ins_Or_Upd]
	 @FIRST_NAME varchar(50) = NULL
	,@MIDDLE_NAME varchar(50) = NULL
	,@LAST_NAME varchar(50) = NULL
	,@PRODUCT_DETAILS varchar(50) = NULL
	,@PRICE_LEFT_DECIMAL_POINT varchar(50) = NULL
	,@PRICE_RIGHT_DECIMAL_POINT varchar(50) = NULL
	,@DATE_TIME varchar(50) = NULL
	,@STREET varchar(50) = NULL
	,@DISTRICT varchar(50) = NULL
	,@CITY varchar(50) = NULL
	,@ZIP varchar(50) = NULL
	,@STATE varchar(50) = NULL
	,@COUNTRY varchar(50) = NULL
	,@PHONE varchar(50) = NULL
	,@CELLULAR varchar(50) = NULL
	,@EMAIL varchar(50) = NULL
	,@COVER_MATERIAL varchar(50) = NULL
	,@ATTEMPT_TO_UPLOAD varchar(50) = NULL
	,@COVER_COLOR varchar(50) = NULL
	,@PAGE_COUNT varchar(50) = NULL
	,@COPIES varchar(50) = NULL
	,@COMMENT varchar(50) = NULL
	,@FINISHING varchar(50) = NULL
	,@COLOR_CORRECT varchar(50) = NULL
	,@IMAGE_COUNT varchar(50) = NULL
	,@CUSTOMER_ID varchar(50) = NULL
	,@CUSTOMER_TITLE varchar(50) = NULL
	,@CUSTOMER_BIRTHDATE varchar(50) = NULL
	,@USED_PRICING_FORMAT varchar(50) = NULL
	,@DECIMAL_SEPARATOR varchar(50) = NULL
	,@BASIC_PAGES_PRICE varchar(50) = NULL
	,@ADDITIONAL_PAGES_PRICE varchar(50) = NULL
	,@ALBUM_BLOCK_PRICE varchar(50) = NULL
	,@COVER_PRICE varchar(50) = NULL
	,@COLOR_CORRECTION_PRICE varchar(50) = NULL
	,@FINISHING_PRICE varchar(50) = NULL
	,@ALBUM_PRICE varchar(50) = NULL
	,@CD_PRICE varchar(50) = NULL
	,@ORDER_PRICE varchar(50) = NULL
	,@TAX_NAME_1 varchar(50) = NULL
	,@TAX_VALUE_1 varchar(50) = NULL
	,@TAX_NAME_2 varchar(50) = NULL
	,@TAX_VALUE_2 varchar(50) = NULL
	,@ORDER_PRICE_INCLUDING_TAXES varchar(50) = NULL
	,@SHIPMENT_PRICE varchar(50) = NULL
	,@TOTAL_PRICE varchar(50) = NULL
	,@DISCOUNT varchar(50) = NULL
	,@PAYED_AMOUNT varchar(50) = NULL
    ,@ID int = NULL output

AS
BEGIN

	DECLARE @TranStarted BIT
	DECLARE @ErrorCode INT

	SET @ErrorCode = 0
	SET @TranStarted = 0

	BEGIN TRANSACTION
	SET @TranStarted = 1


	IF EXISTS (SELECT * FROM [dbo].[Table_3] WHERE [ID]=@ID)
	BEGIN
		-- do an update
		UPDATE [dbo].[Table_3]
		SET  [FIRST_NAME] = @FIRST_NAME
			,[MIDDLE_NAME] = @MIDDLE_NAME
			,[LAST_NAME] = @LAST_NAME
			,[PRODUCT_DETAILS] = @PRODUCT_DETAILS
			,[PRICE_LEFT_DECIMAL_POINT] = @PRICE_LEFT_DECIMAL_POINT
			,[PRICE_RIGHT_DECIMAL_POINT] = @PRICE_RIGHT_DECIMAL_POINT
			,[DATE_TIME] = @DATE_TIME
			,[STREET] = @STREET
			,[DISTRICT] = @DISTRICT
			,[CITY] = @CITY
			,[ZIP] = @ZIP
			,[STATE] = @STATE
			,[COUNTRY] = @COUNTRY
			,[PHONE] = @PHONE
			,[CELLULAR] = @CELLULAR
			,[EMAIL] = @EMAIL
			,[COVER_MATERIAL] = @COVER_MATERIAL
			,[ATTEMPT_TO_UPLOAD] = @ATTEMPT_TO_UPLOAD
			,[COVER_COLOR] = @COVER_COLOR
			,[PAGE_COUNT] = @PAGE_COUNT
			,[COPIES] = @COPIES
			,[COMMENT] = @COMMENT
			,[FINISHING] = @FINISHING
			,[COLOR_CORRECT] = @COLOR_CORRECT
			,[IMAGE_COUNT] = @IMAGE_COUNT
			,[CUSTOMER_ID] = @CUSTOMER_ID
			,[CUSTOMER_TITLE] = @CUSTOMER_TITLE
			,[CUSTOMER_BIRTHDATE] = @CUSTOMER_BIRTHDATE
			,[USED_PRICING_FORMAT] = @USED_PRICING_FORMAT
			,[DECIMAL_SEPARATOR] = @DECIMAL_SEPARATOR
			,[BASIC_PAGES_PRICE] = @BASIC_PAGES_PRICE
			,[ADDITIONAL_PAGES_PRICE] = @ADDITIONAL_PAGES_PRICE
			,[ALBUM_BLOCK_PRICE] = @ALBUM_BLOCK_PRICE
			,[COVER_PRICE] = @COVER_PRICE
			,[COLOR_CORRECTION_PRICE] = @COLOR_CORRECTION_PRICE
			,[FINISHING_PRICE] = @FINISHING_PRICE
			,[ALBUM_PRICE] = @ALBUM_PRICE
			,[CD_PRICE] = @CD_PRICE
			,[ORDER_PRICE] = @ORDER_PRICE
			,[TAX_NAME_1] = @TAX_NAME_1
			,[TAX_VALUE_1] = @TAX_VALUE_1
			,[TAX_NAME_2] = @TAX_NAME_2
			,[TAX_VALUE_2] = @TAX_VALUE_2
			,[ORDER_PRICE_INCLUDING_TAXES] = @ORDER_PRICE_INCLUDING_TAXES
			,[SHIPMENT_PRICE] = @SHIPMENT_PRICE
			,[TOTAL_PRICE] = @TOTAL_PRICE
			,[DISCOUNT] = @DISCOUNT
			,[PAYED_AMOUNT] = @PAYED_AMOUNT
		WHERE [ID]=@ID

	END
	ELSE BEGIN
		-- do an insert
		INSERT INTO [dbo].[Table_3]
			(
			 [FIRST_NAME]
			,[MIDDLE_NAME]
			,[LAST_NAME]
			,[PRODUCT_DETAILS]
			,[PRICE_LEFT_DECIMAL_POINT]
			,[PRICE_RIGHT_DECIMAL_POINT]
			,[DATE_TIME]
			,[STREET]
			,[DISTRICT]
			,[CITY]
			,[ZIP]
			,[STATE]
			,[COUNTRY]
			,[PHONE]
			,[CELLULAR]
			,[EMAIL]
			,[COVER_MATERIAL]
			,[ATTEMPT_TO_UPLOAD]
			,[COVER_COLOR]
			,[PAGE_COUNT]
			,[COPIES]
			,[COMMENT]
			,[FINISHING]
			,[COLOR_CORRECT]
			,[IMAGE_COUNT]
			,[CUSTOMER_ID]
			,[CUSTOMER_TITLE]
			,[CUSTOMER_BIRTHDATE]
			,[USED_PRICING_FORMAT]
			,[DECIMAL_SEPARATOR]
			,[BASIC_PAGES_PRICE]
			,[ADDITIONAL_PAGES_PRICE]
			,[ALBUM_BLOCK_PRICE]
			,[COVER_PRICE]
			,[COLOR_CORRECTION_PRICE]
			,[FINISHING_PRICE]
			,[ALBUM_PRICE]
			,[CD_PRICE]
			,[ORDER_PRICE]
			,[TAX_NAME_1]
			,[TAX_VALUE_1]
			,[TAX_NAME_2]
			,[TAX_VALUE_2]
			,[ORDER_PRICE_INCLUDING_TAXES]
			,[SHIPMENT_PRICE]
			,[TOTAL_PRICE]
			,[DISCOUNT]
			,[PAYED_AMOUNT]
			)
			VALUES 
			(
			 @FIRST_NAME
			,@MIDDLE_NAME
			,@LAST_NAME
			,@PRODUCT_DETAILS
			,@PRICE_LEFT_DECIMAL_POINT
			,@PRICE_RIGHT_DECIMAL_POINT
			,@DATE_TIME
			,@STREET
			,@DISTRICT
			,@CITY
			,@ZIP
			,@STATE
			,@COUNTRY
			,@PHONE
			,@CELLULAR
			,@EMAIL
			,@COVER_MATERIAL
			,@ATTEMPT_TO_UPLOAD
			,@COVER_COLOR
			,@PAGE_COUNT
			,@COPIES
			,@COMMENT
			,@FINISHING
			,@COLOR_CORRECT
			,@IMAGE_COUNT
			,@CUSTOMER_ID
			,@CUSTOMER_TITLE
			,@CUSTOMER_BIRTHDATE
			,@USED_PRICING_FORMAT
			,@DECIMAL_SEPARATOR
			,@BASIC_PAGES_PRICE
			,@ADDITIONAL_PAGES_PRICE
			,@ALBUM_BLOCK_PRICE
			,@COVER_PRICE
			,@COLOR_CORRECTION_PRICE
			,@FINISHING_PRICE
			,@ALBUM_PRICE
			,@CD_PRICE
			,@ORDER_PRICE
			,@TAX_NAME_1
			,@TAX_VALUE_1
			,@TAX_NAME_2
			,@TAX_VALUE_2
			,@ORDER_PRICE_INCLUDING_TAXES
			,@SHIPMENT_PRICE
			,@TOTAL_PRICE
			,@DISCOUNT
			,@PAYED_AMOUNT
			)
	END
		
			
	IF( @@ERROR <> 0 )
	BEGIN
		SET @ErrorCode = -1
		GOTO Cleanup
	END

	IF (@TranStarted = 1)
	BEGIN
		SET @TranStarted = 0
		Select @ID = SCOPE_IDENTITY()
		COMMIT TRANSACTION

	END
	SET @TranStarted = 0

	RETURN 0

END

Cleanup:
	IF (@TranStarted = 1 )
	BEGIN
		SET @TranStarted = 0
		ROLLBACK TRANSACTION
	END

-- Testing
-- Do an insert
-- exec Table_3_Ins_Or_Upd 'Alan',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL

-- Do an update
-- exec Table_3_Ins_Or_Upd 'Alan','Warren',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1

Open in new window

Next we would need to parse our local VB/C# variables into a SQLCommand objects Parameter collection ... Then we can execute the StoredPocedure
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question