Jump to content

Data (Record) Comparison Problem & SQL in .NET


Lee-yoshi

Recommended Posts

Hopefully a simple question this time.I want to compare records between MySQL database & a text file (I.e. search through MySQL Database and see if the record within the text file exists, and if so, update, otherwise insert).Here is my code so far (Getting data from both MYSQL & the text file, i just don't know how to compare records between each of them????

<%@ Page Language="C#" %><%@ import Namespace="System.Data" %><%@ import Namespace="System.Data.Odbc" %><%@ import Namespace="System.IO" %><script runat="server">	void Page_Load(object sender, EventArgs e) {			[MYSQL CONNECTION DATA]			OdbcConnection myConnection = new OdbcConnection(ConnectionString);		OdbcCommand myCommand = new OdbcCommand(CommandText, myConnection);			myConnection.Open();			DataGrid1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);		DataGrid1.DataBind();			myConnection.Close();				string line;	ArrayList RecList = new ArrayList();	using( StreamReader TxtFile = new StreamReader( Server.MapPath("text.txt") ) )	{		line = TxtFile.ReadLine();		while( line != null )		{			line = TxtFile.ReadLine();			RecList.Add( line );		}	}	RecList.TrimToSize();	TheRecList.DataSource = RecList;	TheRecList.DataBind();	}</script><html><head></head><body style="FONT-FAMILY: arial">	<form runat="server">		<asp:datagrid id="DataGrid1" runat="server" CellSpacing="1" GridLines="None" CellPadding="3" BackColor="White" ForeColor="Black" EnableViewState="False">			<HeaderStyle font-bold="True" forecolor="white" backcolor="#4A3C8C"></HeaderStyle>			<ItemStyle backcolor="#DEDFDE"></ItemStyle>		</asp:datagrid>	<asp:datalist id="TheRecList" runat="server" cellspacing="1" cellpadding="0" gridlines="none" backcolor="black" forecolor="blue">	<ItemStyle backcolor="#DEDFDE"></ItemStyle>	<ItemTemplate><%# Container.DataItem %></ItemTemplate>	   </asp:datalist>	</form></body></html>

Please please please help!

Link to comment
Share on other sites

  • 2 weeks later...

Hi!Thanks for replying :)I have changed this slightly so that now it gets the line of data from the text file and searches for one part of it within a record of the mySQL database records. (A UID as you say)The problem is that the mySQL database is over 500,000 records big, so it can only update about 100 records before the page times out (By the time it finds one record), when the text file contains over 100,000 records!How can i alter it so that i can send multiple 'UPDATE' sql statements in ASP.NET in one go here? I've tried adjusting the sql command text so that it adds more than one UPDATE statements together (Split by a ';' character) but it just returns another error :)Originally i was going to check if a record exists and if so, check if it needs updating and then update it if so, otherwise add it. But it just seems quicker to just update the whole record when it's found, otherwise ill have to connect twice, right?Thanks ever so much for any help you can provide!! It's immensly appreciated.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...