|
hii,
you can do so by using keyup event if the keys pressed were contol+v get the data in clibbord here is simple example
private void richTextBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
String PasteText="";
if(e.KeyData==(Keys.Control|Keys.V))
{
PasteText=(String)Clipboard.GetDataObject().GetData(typeof(String));
if(PasteText!=null)
MessageBox.Show(Clipboard.GetDataObject().GetData(typeof(String)).ToString());
}
}
|
|
|
|
|
there's a much easier way.
richTextBox1.Undo();
|
|
|
|
|
HI
My problem is that I am reading a image field from the database table .
then I need to Convert that image field value into a byte[] .
dread = sqlcomm.ExecuteReader();
sqlcomm = new SqlCommand("getCont1" ,sqlconn);
sqlcomm.CommandType = CommandType.StoredProcedure;
dread = sqlcomm.ExecuteReader();
while ( dread.Read())
{ temp= (dread.GetValue(0));
}
this "temp" var store the image field value as object .
now i need to convert this object into byte[] as i have to pass it to a function which take byte[] as parameter.
what I need to do ?
thanks
ss
thanks
|
|
|
|
|
An image SQL server column type translates to a byte array (byte[] )framework type. In your example, the 'temp' variable would have to be declared as byte[] .
You could also use the GetBytes(int index) method on your reader.
For a more complete type mapping table, look here[^].
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
if you want to convert it to byte array you have to serialize it.
using System.Runtime.Serialization.Formatters.Binary;
/*Note i suppose your object is serializable if not add [Serializable] attrubite to your object class*/
BinaryFormatter Serialize=new BinaryFormatter();
MemoryStream stream=new MemoryStream();
byte[]ObjectInBytes=Serialize.Serialize(stream,temp);
//to Deserialize
stream=new MemoryStream(ObjectInBytes);
stream.Seek(0,SeekOrigin.Begin);
temp=(TypeOfYourObject) Serialize.Deserialize(stream);
marcoryos
|
|
|
|
|
|
Hi there, im working on a little client / server application, and im having trouble sending messages between the two. I can send messages no problem as text, but when I serialize an xml class and send that it gives me an error "There is an error in XML document (6, 16)".
Heres the code:
MessageClass - this is what is being serialized and submitted
//--------------------------------------------
//--------------------------------------------
public class messageClass
{
public int clientID;
public int messageType;
public int data;
public messageClass()
{
}
}
//--------------------------------------------
//--------------------------------------------
SERVER code - this is where the class is declared, filled in and submitted. NOTE: I want "data" to be an object, but ive used int here for debugging.
//--------------------------------------------
//--------------------------------------------
Socket listener = (Socket)ar.AsyncState;
client = listener.EndAccept(ar);
Console.WriteLine("client {0}, joined", client.RemoteEndPoint);
// send the user a session ID
string strSessionID = sessionID.ToString();
sessionID++;
//Byte[] byteSessionID = System.Text.Encoding.ASCII.GetBytes(strSessionID.ToCharArray());
//client.Send(byteSessionID, byteSessionID.Length, 0);
messageClass message = new messageClass();
message.clientID = sessionID;
message.messageType = 1;
message.data = 1;
XmlSerializer xml = new XmlSerializer(message.GetType());
MemoryStream transmitStream = new MemoryStream();
xml.Serialize(transmitStream, message);
client.Send(transmitStream.GetBuffer());
Console.WriteLine("Sent message");
listener.BeginAccept(new AsyncCallback(OnConnectRequest), listener);
//--------------------------------------------
//--------------------------------------------
CLIENT - recieving and decoding message, this is where the error is occuring. Message is recieved but will not parse:
//--------------------------------------------
//--------------------------------------------
public void setupRecieveCallback(Socket sock)
{
try
{
AsyncCallback recieveData = new AsyncCallback(OnRecievedData);
sock.BeginReceive(byteBuffer, 0, byteBuffer.Length, SocketFlags.None, recieveData, sock);
}
catch(Exception ex)
{
MessageBox.Show(this, ex.Message, "Setup Recieve callback failed!");
}
}
public void OnRecievedData(IAsyncResult ar)
{
// Socket was the passed in objct
Socket sock = (Socket)ar.AsyncState;
// check if we got any data
try
{
int bytesRecieved = sock.EndReceive(ar);
if (bytesRecieved > 0)
{
// write the data to the list
//String recieved = Encoding.ASCII.GetString(byteBuffer, 0, bytesRecieved);
//##########################
// DO SOMETHING WITH MESSAGE
//##########################
// decode it back to a message class
messageClass myMessage = new messageClass();
XmlSerializer xml = new XmlSerializer(myMessage.GetType());
MemoryStream messageStream = new MemoryStream(byteBuffer);
myMessage = (messageClass)xml.Deserialize(messageStream);
//byte[] buffer = new byte[2048];
//messageStream.Read(buffer, 0, 2048);
int data = myMessage.data;
MessageBox.Show(data.ToString(), "Message");
//MessageBox.Show(recieved, "Message");
// if still connected, reastablish callback
setupRecieveCallback(sock);
}
else
{
// if no data was recieved then the connection is probably dead
Console.WriteLine("client {0}, disconnected", sock.RemoteEndPoint);
sock.Shutdown(SocketShutdown.Both);
sock.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message, "Unusual error during recieve!");
}
}
//--------------------------------------------
//--------------------------------------------
Just for cicks here is the actual message that is recieved, pefore trying to parse:
//--------------------------------------------
//--------------------------------------------
<messageclass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<clientid>2
<messagetype>1
1
//--------------------------------------------
//--------------------------------------------
Any help much appreciated...
|
|
|
|
|
Sorry, forgot to tell it not to treat barckets as HTML. Here is the actual XML that is recieved by the client:
<?xml version="1.0" encoding="utf-8"?>
<messageClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<clientID>2</clientID>
<messageType>1</messageType>
<data>1</data>
</messageClass>
|
|
|
|
|
anyone have a simplified process for doing this. I'm on a intranet and I want only people in my desktop administrator group to gain access to my webforms
thanks,
-Josh
|
|
|
|
|
|
|
Hello,
Is there any way to get a list of stored procedures in an MS Access database?
Been searching for a while and found nothing
Thanks in advance
|
|
|
|
|
Create a view in sql server around the following sql statement and select out of the view in access:
select name from dbo.sysobjects where xtype = 'P' and status >= 0 and name not like 'dtp%' order by name
|
|
|
|
|
Excuse my ignorance, but how am I supposed to create a view in sql server working with MS Access?
Could you be more explicit please? Thanks
|
|
|
|
|
Create a view using query analyzer. Grant select to public. Then access it via a function in vba or directly with a linked ODBC data source.
sql:
Create View storedproclist as
Select name
From dbo.sysobjects
Where xtype = 'P' and status >= 0 and name not like 'dtp%'
Go
Grant Select On storedproclist To Public
|
|
|
|
|
Access doesnt have stored procedures, it has queries and I dont think there is a built-in way of enumerating them.
|
|
|
|
|
Actually, since Access 2000, it does support stored procedures, you can create them through OleDbCommand objects. Problem is there seems to be no way of listing them, unless our cryptic friend's solution works. I yet have to try it.
|
|
|
|
|
I need to make a specific index selected in the glacialist and Im just about to give up, Ive tried as I can using the SelectedIndices (both on the control itself and under Items on it) to make something selected but that seems to be readonly I've tried to do it by using
ListView .SelectedIndicies[0] = <anyint>,
ListView.Items.SelecetIndices[0] = <anyint>,
ListView.SelectedIndicies.add(<anyint> and
ListView.Items.SelectedIndicies.add(<anyint>
This doesn´t give me any errors if something is selected but it doesn´t seem to worj either, It reads from this correctly though.
I appriciate any help to get me on the right track on setting the selected Index
|
|
|
|
|
The ListViewItems in the ListView have a Selected property that's read/write. Set the Selected property for the items individually.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
I have a satellite assembly with all my resources. I need to append a resource file to that satellite assembly. I don't have all the other resource files that make up that satellite assembly, so I need to be able to just append it on the existing assembly. Any ideas? Thanks
|
|
|
|
|
How to check what com ports are available currently in windows?
In C#, or how to use for example method "EnumPorts" from outside of .NET
Thanks
|
|
|
|
|
Which would be considered better practice? Although the first version is smaller the second one uses string builder and breaks it up so that it is easier to distinguish what is being added to the line and avoids hard coding in the actual program. So which would you normally do? Both of these create the same URL in the end.
Stringing it all together like this?
<br />
string strRedirect = "~/Maint/surcharge.aspx?" +<br />
"StartDate=" + cpStartDate.SelectedDate.ToShortDateString() +<br />
"&EndDate=" + cpEndDate.SelectedDate.ToShortDateString() +<br />
"&Market=" + ddlMarkets.SelectedIndex +<br />
"&GroupName=" + cbCustomer.Checked.ToString() +<br />
"&GroupCode=" + cbGroupCode.Checked.ToString() +<br />
"&Abbreviation=" + cbAbbreviation.Checked.ToString();<br />
Or using a string builder to create the URL like this:
<br />
private const string URL_SURCHARGE = "~/Maint/homepage.aspx";<br />
private const string STR_ASP_DELIMITER = "&";<br />
private const string STR_ASP_PARMS = "?";<br />
private const string STR_ASP_EQUALS = "=";<br />
<br />
private const string DF_START_DATE = "StartDate";<br />
private const string DF_END_DATE = "EndDate";<br />
private const string DF_GROUP_CODE = "GroupCode";<br />
private const string DF_ABBREVIATION = "Abbreviation";<br />
private const string DF_GROUP_NAME = "GroupName";<br />
private const string DF_MARKET_TYPE = "Market";<br />
<br />
StringBuilder sbRedirect = new StringBuilder( URL_SURCHARGE );<br />
<br />
sbRedirect.Append( STR_ASP_PARMS );<br />
<br />
sbRedirect.Append( DF_START_DATE );<br />
sbRedirect.Append( STR_ASP_EQUALS );<br />
sbRedirect.Append( cpStartDate.SelectedDate.ToShortDateString() );<br />
sbRedirect.Append( STR_ASP_DELIMITER );<br />
<br />
sbRedirect.Append( DF_END_DATE );<br />
sbRedirect.Append( STR_ASP_EQUALS );<br />
sbRedirect.Append( cpEndDate.SelectedDate.ToShortDateString() );<br />
sbRedirect.Append( STR_ASP_DELIMITER );<br />
<br />
sbRedirect.Append( DF_MARKET_TYPE );<br />
sbRedirect.Append( STR_ASP_EQUALS );<br />
sbRedirect.Append( ddlMarkets.SelectedIndex );<br />
sbRedirect.Append( STR_ASP_DELIMITER );<br />
<br />
sbRedirect.Append( DF_GROUP_NAME );<br />
sbRedirect.Append( STR_ASP_EQUALS );<br />
sbRedirect.Append( cbCustomer.Checked.ToString() );<br />
sbRedirect.Append( STR_ASP_DELIMITER );<br />
<br />
sbRedirect.Append( DF_GROUP_CODE );<br />
sbRedirect.Append( STR_ASP_EQUALS );<br />
sbRedirect.Append( cbGroupCode.Checked.ToString() );<br />
sbRedirect.Append( STR_ASP_DELIMITER );<br />
<br />
sbRedirect.Append( DF_GROUP_CODE );<br />
sbRedirect.Append( STR_ASP_EQUALS );<br />
sbRedirect.Append( cbAbbreviation.Checked.ToString() );<br />
|
|
|
|
|
The best of both worlds:
sbRedirect.AppendFormat("~/Maint/surcharge.aspx?StartDate={0}&EndDate=(1)&Market={2}&GroupName={3}&GroupCode={4}&Abbreviation={5}",
cpStartDate.SelectedDate.ToShortDateString(), cpEndDate.SelectedDate.ToShortDateString(), ddlMarkets.SelectedIndex, cbCustomer.Checked.ToString(), cbGroupCode.Checked.ToString(), cbAbbreviation.Checked.ToString());
|
|
|
|
|
Can someone help me in getting roll down menu code that supports righttoleft.
I would be very thank ful
|
|
|
|
|
I have a requirement of Outlook integration in my C# Desktop application.
I tried the Outlook .Net Connector on CP. I changed the Outlook reference to Outlook 10.0, it run smoothly but whenever I tried to get the inbox mails, it always show one message with repition, instead of showing every message.
Could any one help me out.
Thanks.
The Phantom.
|
|
|
|