|
File class is under System.IO namespace, so you can refer to it like System.IO.File.ReadAllLines(... or add using System.IO directive to your file.
|
|
|
|
|
i got this error
Could not find file 'D:\king.txt'.
but i have word file in my d:
|
|
|
|
|
As the message says, the file cannot be opened. Re-chek the path and the name and if another application is having that file open, close the other application first.
|
|
|
|
|
the file did not open any where in my project...
i gave like this...
string[] datasource = File.ReadAllLines("D:\\king.txt");
Could not find file 'D:\king.txt'.
if i give like this....
string[] datasource = File.ReadAllLines("D:\king.txt");
Error 1 Unrecognized escape sequence //occurs
i gave like this...
string[] datasource = File.ReadAllLines("D:king.txt");
Could not find file 'D:\king.txt'.
|
|
|
|
|
The problem isn't in your code, but the code cannot open the file from the operating system. Check (for example using windows explorer) that:
- the file is on drive D and in the root directory
- the file is named king.txt
- you have privileges to open the file
- the file isn't open in any program, for example in Microsoft Word etc.
|
|
|
|
|
file read successfully but..
reading in this manner ::ࡱ\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0>\0\0\t\0\0\0ࡱ\0\0\0\0\0\0\0\0\0\0\0\0\0
|
|
|
|
|
Are you sure it's a plain text file and not for example in Word format? Open it using notepad. It should answer that question. File-class reads the text as plain text. If the file contains some other format, File class is unable to "translate" it to text.
|
|
|
|
|
i typed "veeserv3" in that word doc... it is not empty...
"Format of the initialization string does not conform to specification starting at index 0."
this error also occured..
|
|
|
|
|
VERY VERY THANKS GENTLE MAN...
I GOT THE RESULT...
|
|
|
|
|
hi. im working on a project that requires inserting, deleting values in the database.
i used the datagridview and edit on the values directly on the grid. it worked but when i try to refresh it, the new values are just appended. example, there are only 2rows in the table. when i click the refresh button, 2rows are appended making it 4 rows of the same value. please help.. need it badly..
another thing is that when i change the name for the data table, directly updating on the datagrid is impossible.
|
|
|
|
|
Sounds like there are some problems in your bindings from the datatable to the datagridview. But without seeing your code, it's hard to say more.
|
|
|
|
|
thanx for the reply..
Dim listquery1 As String
If conn.State = ConnectionState.Open Then conn.Close()
Try
conn.Open()
If cboSubj.SelectedItem.ToString = "ICSM310" And cboSec.SelectedItem.ToString = "Z14" Then
listquery1 = "Select *from sampleList;"
Dim mycmd As New MySqlCommand(listquery1, conn)
mycmd.ExecuteNonQuery()
adptr.SelectCommand = mycmd
adptr.Fill(dtable)
DataGridView1.DataSource = dtable
DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
Else
MsgBox("No list ")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
conn.Close()
this is the first instance for loading the values in the datagrid...
for the "refresh" command
Dim listquery As String
If conn.State = ConnectionState.Open Then conn.Close()
Try
conn.Open()
Try
listquery = "Select *from sampleList;"
Dim mycmd As New MySqlCommand(listquery, conn)
mycmd.ExecuteNonQuery()
adptr.SelectCommand = mycmd
adptr.Fill(dtable)
statusView.DataSource = dtable
statusView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
Catch myerror As MySqlException
MsgBox("There was an error reading from the database: " & myerror.Message)
End Try
Catch myerror As MySqlException
MessageBox.Show("Error connecting to the database: " & myerror.Message)
Finally
If conn.State <> ConnectionState.Closed Then conn.Close()
End Try
End Sub
note that statusView is datagridview
for the mysql adapter and datatable, i declare it at the very beginning of the code..
for me to use the command builder command...
|
|
|
|
|
Few observations:
jetgrageda wrote: mycmd.ExecuteNonQuery()
That should be unnecessary.
Before fill, you could call dtable.Clear()
|
|
|
|
|
thanx.. datatable.clear before fill works..
i owe you..thanx so much..
|
|
|
|
|
You're welcome
|
|
|
|
|
this is my connection string...
SqlConnection objCon = new SqlConnection("Data Source=VEESERV4;Initial Catalog=DemoInven;User ID=sa;Password=sa");
i give data source = veeserv4...
instead of this i have to give one word file their...
and the corresponding text in that word file is taken as data source name...
how can i do this...
|
|
|
|
|
kulandaivel_mca2007 wrote: instead of this i have to give one word file their...
and the corresponding text in that word file is taken as data source name...
Why ??
|
|
|
|
|
projects are submitted in exe file format...
so he(client) not able to change datasource name...
if the datasource name taken from word file...
he can change easily..
|
|
|
|
|
|
Try this
SqlConnection objCon = New SqlConnection(ConfigurationManager.ConnectionStrings["VEESERV4"].ConnectionString)
|
|
|
|
|
I'm writing a kind of terminal program that uses the serial port.
I have it on my "main form", which does most of the communication.
My problem is that I need to add another form that also uses the serie port.
Now to my question / problem.
How can I access the opened serial port on my main form?
//Ola
|
|
|
|
|
Hope you are using VB.NET,
If yes then, make the variable of serial port instance to public instead of friend
e.g.
Instead of
Friend WithEvents SerialPort1 As System.IO.Ports.SerialPort
Use
Public WithEvents SerialPort1 As System.IO.Ports.SerialPort
Then you can access it using My.Forms.main-form-name.SerialPort1
Hope I answered your query
Thanks
Ashu
dnpro
"Very bad programmer"
|
|
|
|
|
Thanks for the advice but unfourtanly I'm not using VB.Net.
I'm writing in c#...
|
|
|
|
|
Same principal, but in C# you make the member public or internal rather than protected or private . For a visual control, you can go to it's properties in the designer and set this via the Modifiers property rather than editing the designer generated code file. Also, the second form will have to have a reference to an instance of the main form; so you'll need to also make that link and then you can access the serial port member as a property of an instance of the main form from the second form. I find the easiest way to establish that link is in the second form's constructor by passing in a reference to the main form:
private MainForm mainForm = null;
public SecondForm(MainForm mainForm) <---- constructor
{
...
this.mainForm = mainForm; <---- save reference to main form
...
}
private void UseSerialPort()
{
SerialPort sp = mainForm.SerialPort; <---- access the member on the main form
}
And on the main form you'd have:
private void OpenSecondForm()
{
SecondForm secondForm = new SecondForm(this); <----- pass the instance of the main form here
secondForm.Show();
}
Remember that even though they are Forms, they are also still just classes like everything else and the controls on them are just members of the class. So, if you wanted one class to be able to access a member from another class you'd have to increase the visibility of that member in the other class and have a reference to an instance of it. So, you're just doing the same thing here but the classes happen to be Forms. Also, it's probably better practice to make an actual property on the main form to control access to the serial port member. This way you could also make it with just a get and have a readonly property.
It's important to consider the ownership and access of objects in the structure of your application. Does it make sense for the serial port object to be 'owned' by the Main Form and shared between it and then second form, or does it make more sense to have a separate class that owns it and from which both forms access it? I can't tell you the answer to that, its just something to keep in mind when you are making these kinds of decisions with your application.
Hope this gets you going!
Keep It Simple Stupid! (KISS)
|
|
|
|
|
Thanks, that helped alot.
It works as I wanted it to.
But I did take youre advice and moved the serial port control to a "ordanary class", witch in terms the two forms can use.
Thanks
Ola
|
|
|
|