| |

VerySource

 Forgot password?
 Register
Search
View: 1642|Reply: 12

DBNull problem

[Copy link]

1

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-2-19 19:00:01
| Show all posts |Read mode
database:
CREATE procedure UserIsExict
@Uid binary (30),
@UserName binary (30) output
as
select @ UserName = UserName from AlbumLogin where Uid = @ Uid
GO
program:
SqlCommand cmd = new SqlCommand ("UserIsExict", conn);
        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Parameters.Add (new SqlParameter ("@ Uid", SqlDbType.Binary, 30));
        cmd.Parameters ["@ Uid"]. Value = Encoding.UTF32.GetBytes (paraUid);

        cmd.Parameters.Add (new SqlParameter ("@ UserName", SqlDbType.Binary, 30));
        cmd.Parameters ["@ UserName"]. Direction = ParameterDirection.Output;

        conn.Open ();
        cmd.ExecuteNonQuery ();
        conn.Close ();

      return Encoding.UTF32.GetString (((byte []) cmd.Parameters ["@ UserName"]. Value));

error:
Cannot cast an object of type "System.DBNull" to type "System.Byte []"
Reply

Use magic Report

0

Threads

32

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 Sweden

Post time: 2020-4-27 09:45:01
| Show all posts
if (cmd.Parameters ["@ UserName"]! = DBNull.Value)
{
 return Encoding.UTF32.GetString (((byte []) cmd.Parameters ["@ UserName"]. Value));

}
else
{
return String.Empty;
}
Reply

Use magic Report

0

Threads

32

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-4-27 10:00:01
| Show all posts
Your return value is null, so no conversion operation is possible
Reply

Use magic Report

0

Threads

119

Posts

67.00

Credits

Newbie

Rank: 1

Credits
67.00

 China

Post time: 2020-4-28 19:30:01
| Show all posts
Judge the return value to deal with it!
Reply

Use magic Report

0

Threads

11

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-4-28 23:15:02
| Show all posts
Treat the reverse value
Reply

Use magic Report

0

Threads

31

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-4-29 12:30:02
| Show all posts
if (Convert.IsDbNull (...))
{
}
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-4-29 13:30:02
| Show all posts
Judge whether it is dbnull or not.
Reply

Use magic Report

0

Threads

23

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-4-29 15:00:02
| Show all posts
error:
Unable to cast object of type "System.DBNull" to type "System.Byte []"
-------------------------
Young people now! I don't know if I analyze them carefully.
Reply

Use magic Report

1

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-5-1 19:15:01
| Show all posts
No, I mean why is it returning DBNull, the value of my database is not empty?
Reply

Use magic Report

1

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-5-2 00:30:01
| Show all posts
I did n’t answer the question, sorry
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list