|
I have an connected, open Socket with ProtocolType = IP. Before doing any sending/receiving, I try to use that Socket to Authenticate the client (in a LAN setting). I get this IOException, "Unable to read data from the transport connection: The connection was closed." When I check the Socket, Connected = True.
The code looks like this:
if (Authenticate)
{
NetworkStream clientStream = new NetworkStream(webSocket,false);
NegotiateStream authStream = new NegotiateStream(clientStream);
try
{
authStream.AuthenticateAsClient((NetworkCredential)CredentialCache.DefaultNetworkCredentials,
"",
ProtectionLevel.None,
TokenImpersonationLevel.Impersonation);
if (!authStream.IsAuthenticated)
{
Console.WriteLine("Authentication failed");
ErrorText = "Authentication using default credentials failed";
return (HttpStatusCode)(-1);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
ErrorText = ex.Message;
return (HttpStatusCode)(-1);
}
}
Any ideas?
|
|
|
|
|
How do I access a Logitech Momo wheel from C# ?
All I need is indicators for left/right turns from the wheel.
Johannes
|
|
|
|
|
Take a look at DirectInput, or XInput. For using these APIs from C# the best wrapper is probably SlimDX.
|
|
|
|
|
Hi
I have successfully applied the networking logic using TCP and UDP protocols both while on internal LAN scenario. Now how can I connect to the computer on network i.e. send a text message to another computer on the internet.
The target computer has the local ip address of 10.10.20.200 which is assigned from a local LAN server which is connected to the internet (you can think of a router too) now I dont know how to access that computer where a server is residing which will receive the message sent from the client.
Hope I was clear to illustrate the scenario and my question.
Regards,
Mujtaba Panjwani
Tiger Softwares
Software Designer and Developer
VB.NET, C#, ASP.NET, VFP
|
|
|
|
|
You need to look up NAT[^]
|
|
|
|
|
Hi
Thanks for the reply.
Can you please give me an example of how to discover NAT for the exact computer, I was thinking of a way to make the program work exactly as yahoo or msn messengers does i.e. sending a message to other computer or sending a file etc.
I will be very thankful for your help.
Regards,
Mujtaba Panjwani
Tiger Softwares
Software Designer and Developer
VB.NET, C#, ASP.NET, VFP
|
|
|
|
|
I'm trying to collect the values from a datagridview in a child form and place them in textboxes located in it's parent form.
I'm using the following statement for one of the values:
txtFirstName.Text = this.finder.dataGridView1.SelectedRows[0].Cells["firstNameDataGridViewTextBoxColumn"].Value.ToString();
As far as I can tell, it should be working. When I run the program, once it gets to this point it throws an error telling me that the values are null. There are no spelling errors.
"finder" is the child form.
Please help.
|
|
|
|
|
Have you tried determining which part of the statement is null?
Are you trying to just get the first selected row and are you sure there is a row selected?
|
|
|
|
|
Sorry, maybe I'm misunderstanding the error message. It's not exactly telling me the value is null...
The message I'm getting is, "Object reference not set to an instance of an object."
It's pointed at "firstNameDataGridViewTextBoxColumn".
After some testing I'm finding the same error on my search statement to fill my datagridview, now, as well:
this.finder.customerTableAdapter.FillByFirstLastPhoneNo(this.finder.edsDBDataSet.Customer, txtLastName.Text, txtFirstName.Text, txtPhone.Text);
If I catch it, however, it continues and fills the datagridview normally, dispite throwing this exception.
I'm still pretty green with this, unfortunately. I'm really not quite sure what exactly is going wrong, since it didn't have this problem earlier.
|
|
|
|
|
The error message usually means that one of the objects has not been created. This could be due to the column not existing or rows not being selected.
Are you checking that SelectedRows.Count is greater than 0? If there are no explicitly selected rows then this could be the problem.
|
|
|
|
|
It looks as though the problem lies in my sql query. I'm not sure how it went wrong, since I've been using it successfully for a week. Reconfiguring the query has not helped, either.
My query is as follows:
SELECT Address, Customer_ID, First_Name, Last_Name, Phone_No FROM Customer
WHERE (Last_Name LIKE @Last_Name) AND (First_Name LIKE @First_Name) AND (Phone_No LIKE @Phone_No)
called by the code I posted previously:
this.finder.customerTableAdapter.FillByFirstLastPhoneNo(this.finder.edsDBDataSet.Customer, txtLastName.Text, txtFirstName.Text, txtPhone.Text);
Thank you for trying to help thus far. I'll keep working on this; maybe someone will have some insight on what's going wrong.
|
|
|
|
|
Dear Sirs:
I have a C# application with a ToolStrip control and a RichTextBox control.
Three of the buttons are for aligning the text, i.e., Align Left, Center, Align Right.
And two of the buttons are for increasing and decreasing Indentation.
I have the CheckOnClick property set to true for these buttons.
My application also has formatting buttons, i.e., Bold, Italic, Underlined and one button for setting a bulleted style.
It was previously suggested that I use the RichTextBox_SelectionChanged event, which in fact works for the formatting buttons and Bullets button.
However, I am running into a dead-end when attempting to write code for the alignment buttons or the 2-Indentation buttons. For example, when I try something like the following code:
<pre>tsBtnAlignLeft.Checked = richTextBoxBody.SelectionAlignment;
tsBtnAlignCtr.Checked = richTextBoxBody.SelectionAlignment;
tsBtnAlignRight.Checked = richTextBoxBody.SelectionAlignment;</pre>
it throws this exception:
"Cannot implicitly convert type System.Windows.Forms.HorizontalAlignment' to 'bool'"
And when I try to add further code in the RTB's SelectionChanged event for the IncreaseIndentation or DecreaseIndentation button's, i.e.,
<code>tsbtnIncreaseIndent.Checked = richTextBoxBody.SelectionIndent;</code>
it throws the following exception:
"Cannot implicitly convert type 'int' to 'bool'"
Can anyone provide a suggestion for getting the Checked property of the alignment buttons and the indentation buttons to reflect the contents of the RichTextBox as the cursor moves over text that is aligned and\or indented?
Thank you in advance.
Richard
|
|
|
|
|
In the SelectionChanged event you will need to analyze the selection alignment and set the Checked property of the left/right/centered buttons to suit.
This is because the SelectionAlignment property can be more than just true or false (boolean), where the checked property is a boolean.
|
|
|
|
|
Thanks Cassandra:
I previously wasn't able to get the syntax to do what I needed to do.
I just kept dancing around the issue in code, but couldn't quite get it right.
That took care of it.
Thanks for responding.
Richard
|
|
|
|
|
hi,
I have this problem which I have been trying to solve for some time but with no result
I have a table in sql server which consists of two columns: LastName and First name, and a result for a "select * from TestTable" is:
Doe John
NULL Mark
Then a I have a piece of code in my WinForms application:
string connString = "server=.;database=Test;Integrated Security=SSPI;";
string sql = "select LastName, FirstName from TestTable";
SqlConnection conn = new SqlConnection(connString);
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet dataset1 = new DataSet();
da.Fill(dataset1, "TestTable");
DataTable dt = dataset1.Tables["TestTable"];
listBox1.DataSource = dt;
if (listBox1.DisplayMember.Length != 0)
{
listBox1.DisplayMember = "LastName";
}
else
{
listBox1.DisplayMember = "FirstName";
}
textBox1.DataBindings.Add("text", dt, "LastName");
textBox2.DataBindings.Add("text", dt, "FirstName");
and it works fine, when there is a NULL value in teh LastName column, in the listBox the FirstName is diplayed. The binding works ok
Now when I alter the table and add another column (Company), the same sql query result looks like that:
Doe John NULL
Smith Mark NULL
NULL NULL Microsoft
Now when I make changes to the code to looke like this:
string connString = "server=.;database=Test;Integrated Security=SSPI;";
string sql = "select LastName, FirstName, Company from TestTable";
SqlConnection conn = new SqlConnection(connString);
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet dataset1 = new DataSet();
da.Fill(dataset1, "TestTable");
DataTable dt = dataset1.Tables["TestTable"];
listBox1.DataSource = dt;
if (listBox1.DisplayMember.Length != 0)
{
listBox1.DisplayMember = "LastName";
}
else
{
listBox1.DisplayMember = "Company";
}
textBox1.DataBindings.Add("text", dt, "LastName");
textBox2.DataBindings.Add("text", dt, "FirstName");
textBox3.DataBindings.Add("text", dt, "Company");
in the listBox I only get the Microsoft entry. The other entries are there but are not visible by the LastName but blank, the binding still works.
http://img103.imageshack.us/my.php?image=50493721ap6.jpg
http://img397.imageshack.us/my.php?image=83000105po0.jpg
Can some help to solve this?
|
|
|
|
|
Since you've binded the listBox1.DisplayMember to company name, it's quite obvious that the first two rows will show nothing since the company is null. What kind of result would you expect?
|
|
|
|
|
so what solution would suggest?
|
|
|
|
|
That depends what do you want to show in the list box? Now you've defined to show only the company name. If there isn't any, nothing is shown.
For example, do you want to show a combined string in the list box? Something like:
Doe, John, Unknown
Smith, Mark, Unknown
Unknown, Unknown, Microsoft
|
|
|
|
|
no, I just want to show a list of LastNames from the table, and if there is a NULL value for the LastName column in a given row then show for that row the value from the column Company
|
|
|
|
|
Okay, then you have at least two options. You can modify your SQL statement and create an additional column and bind to it, like (there may be typos in the examples):
string sql = "select LastName, FirstName, Company, <code>COALESCE(LastName, Company) AS ListData </code>"
+ "from TestTable";
SqlConnection conn = new SqlConnection(connString);
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet dataset1 = new DataSet();
da.Fill(dataset1, "TestTable");
listBox1.DataSource = dataset1.Tables["TestTable"];
listBox1.DisplayMember = "<code>ListData</code>";
or after filling the dataset, you can create a computed column:
string sql = "select LastName, FirstName, Company "
+ "from TestTable";
SqlConnection conn = new SqlConnection(connString);
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet dataset1 = new DataSet();
da.Fill(dataset1, "TestTable");
<code>dataset1.Tables["TestTable"].Columns.Add("ListData",
typeof(string),
"ISNULL(LastName,Company)");</code>
listBox1.DataSource = dataset1.Tables["TestTable"];
listBox1.DisplayMember = "ListData";
Hope it helps.
|
|
|
|
|
the second solution works like a charm many thanks
|
|
|
|
|
You're welcome
|
|
|
|
|
Hi,
I need the output of date time as DateTime format
"s" which means dd-MM-yyTHH:mm:ss using XDate of ZedGraph.
my code is s follow:
double x = (double)new XDate(yearData, monthData, dayData, hourData, minData, secData);
Then write AxisType.Date;
I am getting dd-MM-yy correctly, but HH:mm:ss as 00:00:00.
Can anyone please help to write a correct code to get the
required output?
Thanks.
|
|
|
|
|
|
Hi All,
I am looking for code written in .NET that provides connection between application and telephone.
So that - the telephone will return a code according to input code that it get's from the user.
I'll be happy to get even a little help - if you know something that relate and can help me!!
Thanks.
|
|
|
|
|