.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan
Fauzul Azmi
Asad Ali
Post New Web Links

Can any one tell what's wrong with my code

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net
 
I am going to save a file with .txt extension to my sql. I declared the column name for that as FData and Datatype as Longblob I use the following code to insert the data in to mysql string filePath = Server.MapPath("AchTemplates/genACH.txt"); string filename = Path.GetFileName(filePath); FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); Byte[] bytes = br.ReadBytes((Int32)fs.Length); br.Close(); fs.Close(); string strQuery = "insert into tblFiles(FName,FData) values (@_FName, @_FData)"; MySqlCommand cmd = new MySqlCommand(strQuery); cmd.Parameters.Add("@_FName", MySqlDbType.VarChar).Value = filename; cmd.Parameters.Add("@_FData", MySqlDbType.LongBlob).Value = bytes; InsertUpdateData(cmd); To get the data i used the following code private void download(DataTable dt) { Byte[] bytes = (Byte[])dt.Rows[0]["FData"]; //byte[] bytes = Encoding.UTF8.GetBytes(Convert.ToChar(dt.Rows[0]["FData"])); Response.Buffer = true; Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache);


View Complete Post


More Related Resource Links

Whats wrong with this code, im getting blue line under the createStatus next the switch

  
Error message: Use of unassigned local variable 'createStatus'
 
            MembershipCreateStatus createStatus;
            MembershipUser newUser = Membership.CreateUser(Username.Text, Password.Text, Email.Text);

            switch (createStatus)
            {
                case MembershipCreateStatus.Success:
                    this.CreateAccountResults.Text = "The user account was successfully created!";
                    break;
                case MembershipCreateStatus.DuplicateUserName:
                    this.CreateAccountResults.Text = "There already exists a user with this username.";
                    break;
                case MembershipCreateStatus.DuplicateEmail:
                    this.CreateAccountResults.Text = "There already exists a user with this email address.";
                    break;
                case MembershipCreateStatus.InvalidEmail:
                    this.CreateAccountResults.Text = "There email address you provided in invalid.";
                    break;
                case MembershipCreateStatus.InvalidPassword:
                    this.CreateAccountResults.Text = "The password you provided is invalid. It must be seven characters long and have at least one non-a

Data from text files, What's wrong with my code?

  
Hi all, I have uploaded some tab-delimited .txt files on my web site (actually run on my computer, ie localhost, for now), and now I try to retrieve the data from those files. I do this by calling a vb file containg the sub below. Everything works great, except that the sub won't recognise unicode characters. I can split the resulting string using vbnewline and vbtab, but already in the sub in question, the string doesn't understand the Swedish letters åäö, apostrophes and more. Any help would be greatly appreciated! /Pettrer       Shared Function getTextfile(ByVal FullPath As String, Optional ByRef ErrInfo As String = "") As String Dim strContents As String = "" Dim objReader As StreamReader Try objReader =New StreamReader(FullPath) 'UTF8Encoding? strContents = objReader.ReadToEnd() objReader.Close() ErrInfo = Ex.MessageCatch Ex As Exception End Try Return strContents End Function  

Whats wrong with my ExecuteScalar() Code ? - C#.net - Plz Help !

  
Hi,I downloaded OracleHelper & i'm using it....Now i want to insert a row into a table named 'Sample'.I have 2 textboxes and when i click on the button i need to insert the values from 2 textboxes into the table & here is my code....OracleHelper.ExecuteNonQuery(connectionString, CommandType.Text,"insert into sample (id,name) values(?id,?name);", new OracleParameter("@id", OracleDbType.Int32, Int32.Parse(TextBox1.Text)), new OracleParameter("@name",OracleDbType.Varchar2,20,(TextBox2.Text).ToString()));The error i get is,ORA-00911: invalid character and it shows the error is innew OracleParameter("@name",OracleDbType.Varchar2,20,(TextBox2.Text).ToString())Please guide me !

what is wrong with the below simple code?

  

in a button click I am trying to display a modal popup window
so in the ,cs side button1_click

 Modalpopupextender2.show();

But it is not displaying any thing on the button click. What is missing?

 

<style type="text/css">
     .modalBackground
    {
              background-color:Grey;
              /*Olive; */
              filter:alpha(opacity=70);
              opacity:0.7;
    }
   
     .modalPopup
    {
              background-color:#ffffdd;
              border-width:3px;
              border-style:solid;
              border-color:Gray;
              pad

Annoying SQL exception, probably due to some OO/linq code done wrong

  

I started working on this "already started" project, and I'm having a really annoying error when trying to execute some interactions with SQL Server 2008:

The server failed to resume the transaction

One of these errors I get in this specific method call:

The aspx.cs Call:

   

busProcesso openProcess = new busProcesso(pProcessoId);
    try
    {
        if (openProcess.GetDocument() == null)
        {
            //Irrelevant code.
        }
    }
    catch{ //... }



The Business class (relevant part):
     
   
public class busProcesso : IbusProcesso
     {
        public Processo vProcesso { get; set; }

        RENDBDataContext db;

        public busProcesso()
        {
            vProcesso = new Processo();
        }

        public busProcesso(decimal pProcessoId)
        {
            db = new RENDBDataContext();
            try
            {
                 vProcesso = db.Processos.SingleOrDefault(x => x.Id == pProcessoId);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        public string GetDocument()
        {
            try
            {
   

What's wrong with this code!?!?

  

I had a piece of code running that is fundamentally the same as the below except it uses temporary tables instead of nested queries. Is there something wrong with what I am trying to do? The one with temp tables works fine...

 

select category_a, category_b, count(customer_name) as instances, sum(spend) as spend 
from 
(
select f.customer_name, category_a, category_b, 
case when category_a = category_b then a.spend else f.spend + j.spend end as spend
from 
(
select customer_name, category as category_a, evidencedspend as spend
from fac_spendtest c join dim_customer d on c.customer_key = d.customerkey
join dim_product e 

Exporting data that is in wrong code page in SQL Server

  

Hi,

I have problem, when tryin to export data from SQL Server 2005 using Integration Services.

Sql Server has collation SQL_Latin1_General_CP1_CI_AS (code page 1252), but the actual data is encoded using code page 1257 (SQL_Latin1_General_CP1257_CI_AS). When I look the data using Management Studio, it is displayed wrongly, but when I convert the string to binary, I can see that bytes are encoded using code page 1257. I'm trying to read this data using SSIS 2005, but extended characters are always handled wrongly.

How should I read this data using SSIS?

My first assumption was changing DefaultCodePage to 1257 in my OLE DB Source component (also AlwaysUseDefaultCodePage to true). But without luck.

Also tried to convert data in my SQL Server query using COLLATE, but didn't work.

Is there something I could do to get it working?

 

Thanks


All I see is the asp code, what am I doing wrong?

  

When I load up a .asp page, I just see the code.  How do I get the page to "run"?


Cheers Daniel.


What wrong with this code?

  

SELECT pm.pmnum, FrqDys = CASE pm.frequnit WHEN 'DAYS' THEN 1 * pm.frequency WHEN 'WEEKS' THEN 07 * pm.frequency WHEN 'MONTHS' THEN 30 * pm.frequency WHEN 'YEARS' THEN 365 * pm.frequency ELSE 'WTF'  END
FROM MAXAUS.dbo.pm pm
WHERE (pm.supervisor='GJWHITAKER')

WHILE (SELECT pm.nextdate FROM MAXAUS.dbo.pm pm) IS NOT NULL
   BEGIN
   DECLARE @nxt DATE, @last_date DATE, @counter int, @temp_table TABLE(wrkcd varchar (10),nxtdt DATE)

   SET @nxt = nextdate
   SET @last_date = DATEADD(month,25,now())
   SET @counter= (DATEDIFF(day,@nxt,@last_date))/(SELECT pm.FrqDys FROM MAXAUS.dbo.pm pm)

   While @nxt<=@last_date
      BEGIN
      INSERT INTO @temp_table
      VALUES ((SELECT pm.pmnum FROM MAXAUS.dbo.pm pm), @nxt)
      SELECT @counter = @counter-pm.FrqDys
      IF @counter = 0
      BREAK
      ELSE
      CONTINUE
      END
   END
SELECT tmp.wrkcd, DATEPART(MM,tmp.nxtdt), count(DATEPART(MM,tmp.nxtdt))
FROM @temp_table tmp
GR

Whats wrong with my code?

  

CREATE

 

TABLE [dbo].[TABCPFRF_new](

[IdRegistro] [int]

IDENTITY(1,1)

Whats wrong with my code?

  

I´m trying to run the code bellow, but i get an error

 

sp_msforeachdb

 

' IF ''?'' IN (select name from sys.databases where name in (''Lote_5'', ''Lote_10'', ''Lote_1'') and state = 0)

BEGIN

USE ?

--drop table tabcpfrf_new

IF (EXISTS (select 1 from sys.objects

where name = ''PK_TABCPF_IdRegistro1''))

BEGIN

ALTER TABLE [dbo].[TABCPFRF_new] WITH CHECK ADD CONSTRAINT [FK_TABCPF_TABCODERRO] FOREIGN KEY([CodErro])

REFERENCES [dbo].[TABCODERRO] ([CodErro])

 

ALTER TABLE [dbo].[TABCPFRF_new] CHECK CONSTRAINT [FK_TABCPF_TABCODERRO]

 

ALTER TABLE [dbo].[TABCPFRF_new] WITH CHECK ADD CONSTRAINT [FK_TABCPF_TABLOTE] FOREIGN KEY([IdLote])

REFERENCES [dbo].[TABLOTE] ([IdLote])

 

ALTER TABLE [dbo].[TABCPFRF_new] CHECK CONSTRAINT [FK_TABCPF_TABLOTE]

 

ALTER TABLE [dbo].[TABCPFRF_new] ADD CONSTRAINT [DF_TABCPFRF_DtConsultaRobo] DEFAULT (ge

svcutil ( wrong code) and add service reference (works smoothly)

  

Hi all,

I have a web service at java and I want to consume it with wcf. When I use add service reference to create the proxy everything works ok! When I tried to generate the proxy with svcutil it's generates me two files (*.cs and app.config) which I think is all I need. But nothing works, no errors but when I try to call the services I get nothing!!! But in the case you can't use add service reference (like an authenticated scenario which is the next step for me) what can I do? Why is this happening?Can someone help me?

Thanks.


Code Optimized Web Development Profile (VS 2010 and .NET 4.0 Series)

  
When you first run VS 2010 it prompts you to select an IDE profile to use. The profile you select will configure how tool windows are displayed/docked in the IDE by default and set the default keyboard shortcuts. You can then customize any of these settings by using the Tools->Options menu within the IDE and then override/change them. You can also later reset your profile and pick a different one by choosing the Tools->Import and Export Settings menu command.

Free Code Snippets - ASP.NET

  
You Can Find Useful ASP.NET Related Posts on the above link.

Free Code Snippets - C#

  
Free C# Code Snippets

call JavaScript - jQuery code from ASP.NET Server-Side

  
jQuery got so close to me lately that I can see myself adding the scripts to my project almost unconsciously. The thing is, jQuery is very useful for me, in almost all situations and it has been a do or die enhancement for all my project since I first put my hands on it.

Of course while using it, you encounter few situations which need a bit of research to solve, mostly when you are trying to combine it with some other technologies like: UpdatePanels and ASP.NET Ajax. For instance there are many situations when I would like to run some jQuery magic based on some decision that I make on the server side.

call JavaScript - jQuery code from ASP.NET Server-Side

  
jQuery got so close to me lately that I can see myself adding the scripts to my project almost unconsciously. The thing is, jQuery is very useful for me, in almost all situations and it has been a do or die enhancement for all my project since I first put my hands on it.

Of course while using it, you encounter few situations which need a bit of research to solve, mostly when you are trying to combine it with some other technologies like: UpdatePanels and ASP.NET Ajax. For instance there are many situations when I would like to run some jQuery magic based on some decision that I make on the server side
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend