C# infinite rows reading [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
As mentioned in title, I'm basically developing a program (Server/client)
where the server inserts some data in a table row, and the client is reading the data.
while (true)
{
string Command = ReadData();
//Read row
if (Command != string.Empty)
{
switch(Command)
{
case "Connection":
Console.writeLine("Connected !");
break;
}
}
else
{
console.writeLine("No data were found ! ");
}
}
The Readata();function only returns a string if found in a row.
The default Data in that Row is Null - there is no stored data in that row until the server inserts some information like a Command on it.
The Client will always read that row and for each time it finds something other than null it will execute some code.
Won't that break the program while executed?
I hope my question is clear, and have a nice day!

It won't break the program if the client appropriately handles the case where the row doesn't exist.
For example (pseudo code)
loop {
checkForRow();
if (row.exists) {
readRowData();
clearRowData();
}
}

Related

How to close program if , if else ,equals no [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I just started C#.
I can't seem to find a way of the program closing it if the, if else, equals no.
I've tried :
-> System.Environment.Exit(1);
-> public static void Exit ();
A part of the Code:
Console.WriteLine("Jes/No");
string input = Console.ReadLine();
if (input == "Jes")
{
Console.WriteLine("Welcome to the Apex Libary");
}
if (input == "No")
{
________________________
}
The Blanks :______________ , are a space holder so that I know where to put the code.
Use :
Environment.Exit(0);
This command is used to close the application by providing an exit code.

How to export CSV to Db with headers in C#? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
How to export csv to db in C#. It works fine when you have a plain text simple text. But in my case I need to parse headers as single row.
There are many options!
use some driver custom functions (depends on your database)
use a [schema.ini](
https://learn.microsoft.com/en-us/sql/odbc/microsoft/schema-ini-file-text-file-driver)
do it manually ...
You can do it manually with while iteration. Before using loop, you should read csv file from path with StreamReader.
For example:
using(var csvReader = new StreamReader(System.IO.File.OpenRead("your file path")))
{
while (!csvReader.EndOfStream)
{
var rows = csvReader.ReadLine();
var columns = rows.Split(';');
if(values.Length > 1)
{
// Your logic getting values to save db
}
}
}

Check if any form fields have changed upon saving asp.net c# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I've got a large .net form with hundreds of input fields, sometimes users navigate off the form page without saving, what's the best way to check if a field value has changed when they try to navigate away? some c# function or javascript?
Don't take the control out of the users hand :-)
Ask him on exit, if he wants to save the changes. Maybe he did some changes by mistake, which you don't want to save.
You can achieve this by Javascript/Jquery. Something like:
$(document).ready(function() {
formmodified=0;
$('form *').change(function(){
formmodified=1;
});
window.onbeforeunload = confirmExit;
function confirmExit() {
if (formmodified == 1) {
return "New information not saved. Do you wish to leave the page?";
}
}
$("input[name='commit']").click(function() {
formmodified = 0;
});
});

Converting a byte array to "ToString()" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am trying to convert a type array to a string. I have done my research and nothing seems to be working for me. Here is my code,
if (row.Table.Columns.Contains("DataRow") && !Convert.IsDBNull(row["DataRow"]))
{
byte[] rowData;
if(Byte.TryParse(row["DataRow"].ToString(), out rowData)
{
dbModel.DataRow= rowData;
}
else
{
return null;
}
I am trying to initialize and assign the array to the "host" and hold the value throughout the if statement. DataRow holds varBinary(128), the arguments in the second if statement give out an error that reads "The best overloaded method match for 'byte.TryParse(string, out byte)' has some invalid arguments
If you really are reading an array, try this:
if (row["DataRow"] != DBNull.Value)
{
byte[] data = (byte[])row["DataRow"];
}
If its coming back from the provider as a byte array, that will change it from object back to a byte array.

Reading a text file and getting information by line C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
When reading a text file by using StreamReader, how can I get information from the contents on that line
for example:
Line 1: Hi there, my name is bob
Line 2: 1234563 90312
Line 3: I jumped over the moon
How would I detect 90312 on line 2? or anything else I may want on other lines?
Thanks.
You can check whether the current line contains some specific string. Such as:
string line;
using (StreamReader reader = new StreamReader("file.txt"))
{
line = reader.ReadLine();
if(line.Contains("90312"))
{
// Do something fancy here.
}
}
As far as I understand your question, you probably want to read a line into a variable and then tokenize it based on word-to-word basis.
You can use > stringObject.Split(' '); where, stringObject contains the line in question.

Categories