Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
S

si_69

@si_69
About
Posts
257
Topics
163
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Optimising XML
    S si_69

    Hi All I am trying to find a way to optimise the below code for my web service In my webservice i recieve 10 different XML files, each xml file is always the same format, at the moment i have 10 different methods to handle each one, the below code is an example of one of the methods. The only difference between the methods are the local variables and the node attributes. Instead of having 10 methods almost identical i would like to have just one. Can anyone advise on the best way to achieve this ? thanks

    public void NavigateXmlSessionData(XPathNavigator xPathNav)
    {

            xPathNav.MoveToRoot(); 
    
            xPathNav.MoveToFirstChild(); 
    
    
            xPathNav.MoveToFirstChild(); 
            string  description, personId; 
           // initalise vars 
            description = ""; 
            personId = ""; 
    
            do 
            { 
                //display the child nodes 
                if (xPathNav.MoveToFirstChild()) 
                { 
                    while (xPathNav.MoveToNext()) 
                    { 
    
                        switch (xPathNav.Name) 
                        { 
                            #region NodeAttributes 
                            case "Description": 
                                { 
                                    StringBuilder strBuild = new StringBuilder(xPathNav.Value, 200); 
                                    description = strBuild.Replace('\\'', ' ').ToString(); 
                                    break; 
                                } 
                            case "PersonId": 
                                { 
                                    StringBuilder strBuild = new StringBuilder(xPathNav.Value, 200); 
                                    personId = strBuild.Replace('\\'', ' ').ToString(); 
                                    break; 
                                } 
                                #endregion 
    
    
                        } 
    
                    } 
                    //move back to the parent 
                    xPathNav.MoveToParent(); 
                } 
                ProcessRecord(); 
                // initalise vars 
                description = ""; 
                personId = ""; 
    
    
            } while (xPathNav.MoveToNext()); 
        }
    
    C# xml tutorial question

  • c# calling Stored Procedures
    S si_69

    Hi All I am trying to create a generic method for calling stored procedures I would like to pass in the Parameters in via an array At the moment i am having trouble adding the parameters to the SqlCommand This is what i have so far Can anyone advise thanks Simon Calling the method string[] paramNames = new string[1]; paramNames[0] = "@date = 2012-1-1"; string err="";

    WriteToDatabase("exec LoadData", CommandType.StoredProcedure, paramNames, out err);

    Method

    public static bool WriteToDatabase(
    string sql,
    CommandType commandType,
    string[] paramNames,
    out string errorText)
    {
    bool success = false;
    errorText = "";
    try
    {
    using (SqlConnection connection = new SqlConnection(ConnectionString))
    {
    connection.Open();
    List parameters = new List();

                foreach (string paramName in paramNames) 
                { 
                    parameters.Add(new SqlParameter() { ParameterName = paramName }); 
                } 
    
                using (SqlCommand command = new SqlCommand() 
                { 
                    Connection = connection, 
                    CommandText = sql, 
                    CommandType = commandType, 
                    Parameters = parameters 
    
                }) 
                 command.ExecuteNonQuery();   
    
                 connection.Close(); 
            } 
    
    
        }
    
    C# csharp database data-structures

  • Reading Null values in a byte array
    S si_69

    Hi All I am trying to loop through a byte array (sample below) reading the values to then insert those into a database I loop through keeping track of the position

    byte[] data;
    long position=0;
    while (position < data.Length)
    {
    position = Conversion.Extract(data, out mydata, position);
    position = Conversion.Extract(data, out nextitem, position);
    }

    public static long Extract(byte\[\] message, out int variable, long position) 
    { 
        const int length = 4; // the length of an int 
    
        if (message.Length >= position + length) 
        { 
            variable = BitConverter.ToInt32(message, (int)position); 
            return position + length; 
        } 
    
        // there was a problem 
        variable = 0; 
        return -1; 
    } 
    

    The data i have contains some null values, how can i extract these and successfully move onto the next value. At present if i come across a null value i dont know how to detect this and move onto the next item. Can anyone help at all Thanks Simon

    6F 72 67 61 6E 69 73 61 74 69 6F 6E 49 64 3D 33
    26 10 00 00 00 50 65 6F 70 6C 65 50 65 6F 70 6C
    65 4C 69 6E 6B 6A 08 00 00 09 00 00 00 0E 00 00
    00 53 65 6E 69 6F 72 50 65 72 73 6F 6E 49 64 0E
    00 00 00 4A 75 6E 69 6F 72 50 65 72 73 6F 6E 49
    64 11 00 00 00 53 65 6E 69 6F 72 50 65 72 73 6F
    6E 4D 69 73 49 64 11 00 00 00 4A 75 6E 69 6F 72
    50 65 72 73 6F 6E 4D 69 73 49 64 08 00 00 00 4C
    69 6E 6B 54 79 70 65 16 00 00 00 50 61 72 65 6E
    74 61 6C 52 65 73 70 6F 6E 73 69 62 69 6C 69 74
    79 08 00 00 00 50 72 69 6F 72 69 74 79 0B 00 00
    00 4C 61 73 74 55 70 64 61 74 65 64 07 00 00 00
    44 65 6C 65 74 65 64 01 00 00 00 D7 0A 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 01 80 C3 29
    C6 85 BF CE 08 00 02 00 00 00 3C 0C 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 F0 83 76 C6
    85 BF CE 08 00 03 00 00 00 3C 0C 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 C0 0E 76 C6 85
    BF CE 08 00 04 00 00 00 67 0B 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 01 70 CA 4B C6 85 BF
    CE 08 00 05 00 00 00 67 0B 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 02 70 CA 4B C6 85 BF CE
    08 00 06 00 00 00 9B 08 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 02 C0 BE B2 C5 85 BF CE 08
    00 06 00 00 00 AD 09 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 02 10 6D F5 C5 85 BF CE 08 00
    06 00 00 00 3F 0A 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 02 80 59 11 C6 85 BF CE 08 00 07
    00 00 00 E3 0A 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 01 C0 D0 2C

    C# help database data-structures tutorial question

  • ArgumentException
    S si_69

    Hi I have a web method (see below) which accepts an integer as a parameter. I want to be able to catch the error if a paramter is not provided. I thought using catch (ArgumentException) would do the job Is there anything else i should be doing to be able to catch errors like this ? thanks Simon

    \[WebMethod\]
    public DataSet GetOrganisation(int organisationId)
    {
    
        DataSet ds = new DataSet();
        try
        {
    

    .....

        }
        catch (MySql.Data.MySqlClient.MySqlException ex)
        {
            WriteToLog(organisationId.ToString(), "", "GetOrganisation", ex.Message);
        }
        catch (ArgumentException argerr)
        {
            WriteToLog(organisationId.ToString(), "", "GetOrganisation", argerr.Message);
        }
    
       
        return ds;
    }
    
    C# mysql help question career

  • CToolbar
    S si_69

    Hi i am using a toolbar in a PropertyPage as part of a wizard This works fine the first time, but if i access the wizard again, and that particular page then the toolbar fails to load Can anyone help im using the below code

    if(!m_toolBar3.CreateEx(this, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS |CBRS_FLYBY | TBBS_BUTTON) || !m_toolBar3.LoadToolBar(IDR_TOOLBAR1))
    AfxMessageBox("failed");

    		// a small gap between buttons	
    m\_toolBar3.SetButtonInfo(m\_toolBar3.CommandToIndex(ID\_FILE\_SAVE)+1,ID\_SEPARATOR,TBBS\_SEPARATOR,5);
    m\_toolBar3.SetButtonInfo(m\_toolBar3.CommandToIndex(ID\_EDIT\_DELETE)+1,ID\_SEPARATOR,TBBS\_SEPARATOR,5);
    m\_toolBar3.SetButtonInfo(m\_toolBar3.CommandToIndex(ID\_EDIT\_UNDO)+1,ID\_SEPARATOR,TBBS\_SEPARATOR,5);
    m\_toolBar3.SetButtonInfo(m\_toolBar3.CommandToIndex(ID\_APP\_ABOUT)+1,ID\_SEPARATOR,TBBS\_SEPARATOR,5);
    m\_toolBar3.SetButtonInfo(m\_toolBar3.CommandToIndex(ID\_COLOUR)+1,ID\_SEPARATOR,TBBS\_SEPARATOR,5);
    m\_toolBar3.SetButtonStyle(m\_toolBar3.CommandToIndex(ID\_BOLD),TBBS\_CHECKBOX);
    m\_toolBar3.SetButtonStyle(m\_toolBar3.CommandToIndex(ID\_UNDERLINE),TBBS\_CHECKBOX);
    m\_toolBar3.SetButtonStyle(m\_toolBar3.CommandToIndex(ID\_ITALIC),TBBS\_CHECKBOX);
    m\_toolBar3.SetButtonStyle(m\_toolBar3.CommandToIndex(ID\_PARAGRAPH\_LEFT),TBBS\_CHECKGROUP);
    m\_toolBar3.SetButtonStyle(m\_toolBar3.CommandToIndex(ID\_PARAGRAPH\_CENTER),TBBS\_CHECKGROUP);
    m\_toolBar3.SetButtonStyle(m\_toolBar3.CommandToIndex(ID\_PARAGRAPH\_RIGHT),TBBS\_CHECKGROUP);
    m\_toolBar3.SetButtonStyle(m\_toolBar3.CommandToIndex(ID\_PARAGRAPH\_BULLETED),TBBS\_CHECKBOX);
    
        RepositionBars(AFX\_IDW\_CONTROLBAR\_FIRST, AFX\_IDW\_CONTROLBAR\_LAST,0);
    m\_toolBar3.MoveWindow( 18, 134,450, 30, 1 );
    

    thanks Simon

    C / C++ / MFC help

  • red squiggly line - misspelt words
    S si_69

    Hi Does anyone know how to get/use the red squiggly line used in Ms word for spelling mistakes thanks simon

    C / C++ / MFC tutorial

  • Line break in CRichEdit Control
    S si_69

    hi please ignore this, i have worked it out noe :)

    C / C++ / MFC help

  • Line break in CRichEdit Control
    S si_69

    Hi I am using m_richEditCtrl.SetSel(s,e); sel = m_richEditCtrl.GetSelText(); to get the text of a selected item in a RichEdit Control I having problems detecting if the selected text contains a line break or carriage return can anyone help thanks Simon

    C / C++ / MFC help

  • Connection String problem
    S si_69

    Hi I am having trouble building my database connection string, i have to read the server name, db, un, and password from an INI file (dont ask) This is no problem, but im having trouble using these values to build my connection string currently im getting the error A field initializer cannont reference the nonstatic field, method or property my knowledge of C# is basic to say the least, can anyone point me in the correct diretion or help at all? thanks Simon Code Below

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Web;
    using System.Web.Services;
    using System.Data.SqlClient;
    using System.IO;
    using System.Text;
    using System.Net;
    using System.Xml;

    using System.Runtime.InteropServices;
    namespace WebService1
    {
    /// /// Summary description for Service1.
    ///
    public class Service1 : System.Web.Services.WebService
    {
    string con;
    string ini_path;
    string tc_server="";
    string tc_database="";
    string tc_un="";
    string tc_pwd="";
    string tc_server_str="";
    public Service1()
    {
    //CODEGEN: This call is required by the ASP.NET Web Services Designer
    InitializeComponent();
    ReadIniSettings();
    con=CreateConnectionString();
    }
    SqlConnection myConnectionCP2 = new SqlConnection(con);

    	#region Component Designer generated code
    	
    	//Required by the Web Services Designer 
    	private IContainer components = null;
    			
    	/// /// Required method for Designer support - do not modify
    	/// the contents of this method with the code editor.
    	/// 
    	private void InitializeComponent()
    	{
    	}
    
    	/// /// Clean up any resources being used.
    	/// 
    	protected override void Dispose( bool disposing )
    	{
    		if(disposing && components != null)
    		{
    			components.Dispose();
    		}
    		base.Dispose(disposing);		
    	}
    	
    	#endregion
    	void ReadIniSettings()
    	{
    		ini\_path="F:\\\\Web\\\\tr\\\\htdocs\\\\cpbl4\\\\";
    		tc\_server = IniFile.ReadValue(ini\_path,"TC","Server");
    		tc\_database=IniFile.ReadValue(ini\_path,"TC","Database");
    		tc\_un=IniFile.ReadValue(ini\_path,"TC","UN");
    		tc\_pwd=IniFile.ReadValue(ini\_path,"TC","Pwd");
    	
    	}
    	string CreateConnectionString()
    	{
    		tc\_server\_str=SQLConn.CreateConnStr(tc\_server,tc\_un,tc\_pwd,tc\_database);
    		return tc\_server\_str;
    		
    	}
    }
    public class IniFile
    {
    	\[DllImport("kernel32")\]
    	private static extern long WritePrivateP
    
    C# help csharp database asp-net wcf

  • Disabling Keypress on MessageBox
    S si_69

    Hi I have an application where a user types a message into an edit control, after they have exceeded a certain number of characters they are shown a warning. ie AfxMessageBox("you have exceeded X number of characters"); it seems that if the user is typing fast by pressing return of the space bar this is calling the OnOK and quickly turning off the message box so the users are not seeing the warning. Does anyone know if there is a way you can disable the return key and the space key on Afxmessagebox ? i could create a custom dialog to do this but that seems a long way round can anyone help thanks Simon

    C / C++ / MFC help question

  • Using OPENROWSET
    S si_69

    Hi I am trying to import a CSVs file using OPENROWSET and import this into a database my problem is the CSV files may contain a varying number of columns i have tried using SELECT BulkColumn FROM OPENROWSET (BULK '\\10.1.2.107\rp_uploaded_files\file.csv', SINGLE_CLOB) MyFile but this puts all the values into one fields i have also tried set @string ='BULK INSERT CSVTest FROM ''\\10.1.2.107\rp_uploaded_files\'+@file+''' WITH (FIELDTERMINATOR = '','',ROWTERMINATOR = ''\n'')' exec (@string) but this requires the destintation table to have the same number of columns as the import file Can anyone advise thanks Simon

    Database database help

  • disabling finish button on property sheet wizard
    S si_69

    Hi Can anyone tell me how i can disable the finish button on a property sheet wizard ? on my property page i initally define the buttons like

    BOOL CPage::OnSetActive()
    {
    CWizard* pParent = (CWizard*)GetParent();
    ASSERT_KINDOF(CWizard, pParent);
    pParent->SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH);

    return CPropertyPage::OnSetActive();
    

    }

    I then want to disable the finish button until a certain task has completed i.e

    void CPage::OnBnClickedBstart()
    {
    GetDlgItem(ID_WIZFINISH)->EnableWindow(FALSE);
    DoSomething();
    GetDlgItem(ID_WIZFINISH)->EnableWindow(TRUE);

    }

    i have also tried adding

    CWnd *pWnd = GetDlgItem (ID_WIZFINISH);
    pWnd->EnableWindow(FALSE);

    but get the same problem Can anyone help at all thanks Simon

    C / C++ / MFC help question

  • CEdit
    S si_69

    _AnsHUMAN_ wrote:

    Is it a single line edit control?

    No it is a multiline and the want return property is set to true Any ideas ? Simon

    C / C++ / MFC help

  • CEdit
    S si_69

    Hi I have tried using m_c_message.SetLimit(3000); but the same happens as soons as i exceed 256 charc the cursor jumps to the start Can anyone help thanks Simon

    C / C++ / MFC help

  • CEdit
    S si_69

    Hi I am using a CEdit control, however when the user exceeds 256 characters, the cursor jumps to the start of the control rather than continuing on Can anyone help at all thanks Simon

    C / C++ / MFC help

  • Edit Control
    S si_69

    thx

    C / C++ / MFC help

  • Edit Control
    S si_69

    _AnShUmAn_ wrote:

    Check out SetLimitText(UINT /*param*/) API

    thanks, i am already using SetLimitText my problem is not the size of text allowed as i can exceed 256, it is when i reach 256 characters the cursor jumps to the start

    C / C++ / MFC help

  • Edit Control
    S si_69

    Hi I have an edit control which i have a character counter on this works fine, but when i exceed 256 chars the cursor jumps to the start of the edit control For my counter i am using void CMyMessagePage::OnEnChangeEMsg() { UpdateData(TRUE); int nBytes = lstrlen(m_message); CString len; len.Format("%d",nBytes); m_sms_written = len; UpdateData(FALSE); } Can anyone help thanks Simon

    C / C++ / MFC help

  • Searching for a Manifest File
    S si_69

    _AnShUmAn_ wrote:

    Try BOOL PathFileExists(LPCTSTR pszPath);

    thanks

    C / C++ / MFC algorithms help

  • Searching for a Manifest File
    S si_69

    Hi I am trying to check for the existance of the file "Microsoft.VC80.CRT.manifest" within a user defined folder to try and find it i am using dwResult = SearchPath(lpbPath,lpbFilename,lpbExt,dwBufferSize, szBuffer, &lpbPEnd); where lpbFilename = "Microsoft.VC80.CRT" and lpbExt = ".manifest" lpbPath with be a user defined path passed to the function however nothing is returned,i use this function to search for traditional file type (i.e something.ext) and this works fine can anyone help at all thanks simon

    C / C++ / MFC algorithms help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups