i have designed a windows forms which has a textbox in it,in that textbox i will enter path and on click of button i will bind that data to database(mysql) and i am done with it.but if the entered path contains '\'(escape character) it will be ignored while binding for e.g, if E:\folder is path it will be entered as E:folder into database,and user wont enter \\ when entering a path,how to solve this prob,

private string filepath(string FilePath)
        {
            char[] splitpath=FilePath.ToCharArray();;
            for(int i=0;i<splitpath.Length;i++)
            {
                char s=splitpath[i];
                if (c == '\')//error at this line
                   {
                 string path= s.Replace('\' , '\\');//error at this line also
                   }
            }
        return path;
        }

errors are
too many character in character literal(CS1012)
new line in constant(CS1010)
unexpected character(CS1056)

thanks in advance,

Recommended Answers

All 9 Replies

use "@" sign with the string containing path and then pass to the sql command

PlotDriverFilePath=PlotDriverFilePath.Insert(0,"@");
after doing this i passed it to mysql command but it the value which got added to mysql was
@E:\foldername

use "@" sign with the string containing path and then pass to the sql command

PlotDriverFilePath=PlotDriverFilePath.Insert(0,"@");
after doing this i passed it to mysql command but it the value which got added to mysql was
@E:\foldername

look what i was saying PlotDriverFilePath=@PlotDriverFilePath; check like this

look what i was saying PlotDriverFilePath=@PlotDriverFilePath; check like this

i tried as you said,its not working:(:'(

ok can you show me your code...

ok can you show me your code...

public int Insert(int printerid,int id,string FilePath,string FileName)
	   {
	   	MySqlCommand cmd=null;
	   	try 
	   	{
	   		con.Open();
	   		string str=string.Format("INSERT INTO tbl_Driver(tbl_PrinterName_id_fk,tbl_id_fk,tbl_filePath,tbl_fileName)VALUES('{0}','{1}','{2}','{3}')",printerid,id,FilePath,FileName);
	   		cmd=new MySqlCommand(str,con);
	   		return cmd.ExecuteNonQuery();
	   	} 
	   	catch (Exception ex) 
	   	{
	   		throw ex;
	   	} 
	   	finally 
	   	{
	   		if(con!=null)
	    		{
	    			con.Close();
	    			con.Dispose();
	    		}
	    		if(cmd!=null)
	    		{
	    			cmd.Dispose();
	    		}
	   	}
	   }

ok you might be passing value FilePath="c:\folder\file"; if it is so then change line number 7 to

string str=string.Format("INSERT INTO tbl_Driver(tbl_PrinterName_id_fk,tbl_id_fk,tbl_filePath,tbl_fileName)VALUES('{0}','{1}','{2}','{3}')",printerid,id,@FilePath,FileName);

add "@" symbol before filepath while insertion

ok you might be passing value FilePath="c:\folder\file"; if it is so then change line number 7 to

string str=string.Format("INSERT INTO tbl_Driver(tbl_PrinterName_id_fk,tbl_id_fk,tbl_filePath,tbl_fileName)VALUES('{0}','{1}','{2}','{3}')",printerid,id,@FilePath,FileName);

add "@" symbol before filepath while insertion

sorry,to tell this i tried that but still not working,but i have an idea which i dont know how to implement

public string PlotDriverFilePath
{
	get {return this.PlotDriverFilePathTextBox.Text.Trim();}//when returning the value from here can i add @symbol,i can do it if i directly pass the path something like str path=@"c:\path"; it works fine but i dont know how to add @symbol in properties,you have any idea how to do this
        set {this.PlotDriverFilePathTextBox.Text = value;}
		}

and thank you very much for trying to help me out,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.