All Entries Tagged With: "read"
Illustrate the use of ExecuteReader method in C#
The ExecuteReader() method executes commands that return rows, such as a SQL SELECT statement. The returned rows are located in an OdbcDataReader, an OleDbDataReader, a SqlDataReader, or an OracleDataReader, depending on which Data Provider you are using.
string cmdString = "SELECT user_name, pass_word FROM LogIn ";
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.Connection = sqlConnection;
sqlCommand.CommandType = CommandType.Text;
sqlCommand.CommandText = cmdString;
sqlDataReader [...]
Reading from Filehandles in Perl
open (FILE, "/tmp/file") or die("Cannot open file: $!");
while (<FILE>) {
chomp;
print "The line just read was: $_\n";
}
Working with Comma-Separated Values in C# .NET
The example uses comma-separated values, loading them into a List object.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace CommaValues
{
class Program
{
private static List<Dictionary<string, string>> GetData(
out List<string> columns)
{
[...]
Reading Data from an Input Stream in C# .NET
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace StreamRead
{
class Program
{
static void Main(string[] args)
{
string line;
[...]
Reading Data from Random Access Files
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ReadFile
{
class Program
{
static void Main(string[] args)
{
byte[] byData = new byte[200];
[...]
ERROR 1099 (HY000): Table ‘TABLENAME′ was locked with a READ lock and can’t be up dated
This error occurs when you try to insert data into a table that has been locked for reading only.
Lock table:
mysql> LOCK TABLES TABLEproducts READ;
Query OK, 0 rows affected (0.00 sec)
Trying to insert into TABLEproducts creates the error:
INSERT INTO TABLEproducts(comment) VALUES(’READ LOCK BY MYSELF’);
Error:
ERROR 1099 (HY000): Table ‘TABLEproducts′ was locked with a READ lock and can’t [...]
Read assembly attributes in csharp
To get the attributes for an assembly we can call the GetCustomAttributes() method on the Assembly class. The GetCustomAttribute takes a boolean value as parameter which indicates whether to get inherited attributes; the GetCustomAttribute class implements the ICustomAttributeProvider interface. The assembly class ignores the boolean parameter because there is no inheritance for assemblies.
Assembly asmb = [...]
ReflectionOnlyLoad and ReflectionOnlyLoadFrom in ASP.NET
The ReflectionOnlyLoad and ReflectionOnlyLoadFrom methods are built into ASP.NET 2.0 to load assemblies only to interrogate/read information in the assembly. We cannot execute the code in the assembly or create new instances of the assembly when assemblies are loaded using the ReflectionOnlyLoad and ReflectionOnlyLoadFrom methods. These functions reduce the overhead of loading an assembly that [...]
Loop through an array and read values in Javascript
To loop through all entries of an array and read their values, we can use a for loop to build an incrementing index counter, limited by the length of the array.
Example:
var myArray = ["Mani", "Kaka", "Biryani", "Mad"];
for (var i = 0; i < myArray.length; i++) {
document.write("Item " + i + " is:" + myArray[i] + [...]
Read file up to 1024 bytes of data in csharp
Stream stream = File.OpenRead(@"C:\data\file.xml");
int bytesToRead = 1024;
int bytesRead = 0;
byte [ ] buffer = new byte [bytesToRead];
// Fill up the buffer repeatedly until we reach the end of file
do {
bytesRead = stream.Read(buffer, 0, bytesToRead);
Console.Write(Encoding.ASCII.GetChars(buffer,0, bytesRead));
} while (bytesToRead == bytesRead);
stream.Close( );