Showing posts with label wrong. Show all posts
Showing posts with label wrong. Show all posts

Monday, March 19, 2012

I update SqlExpress database but i don't see the records

Hi everybody! I 'm facing a strange problem and i hope someone could help me understand what i'm doing wrong.

The situation has as follows:

1. I make a new windows project in VB .Net 2005 and add a listbox to form1

2. With "Add new Item" from the solution explorer I add a new Sql Database from the templates to the project (e.g. MyDatabase1.mdf)

3. I add a table to the SQL Database e.g. Books - with 2 only fields (BookID and BookDescription) and I add some records to the table

4. I add a new DataSource to the project and I bind the LIstBox to the table Books.

5. I add two buttons to the project. Button1 adds a new book, Button2 gives me record by record the books in the table (e.g. 1-Vb for begginers, 2-.Net for begginers etc.)

6. I Run the project and I add a new record to the table through button1. With button2 I confirm the record is added to the table (3-Vb for me)

Till here, everything works fine...

7. I close the project. I open the table Books to see for the new record (VB for me). There is no record in the Database!

Any idea?

P.S. I've done all possible ways to add the new record (with tableadapter and with a SqlCommand). In both ways the record in runtime is added to the table and it can be confirmed.

But when I close the project and try to find it , there is no record at all!

Hi,

make sure you call the update method on your SQLDataAdapter. Otherwise the data won′t be updated though the Dataset you are working with a in its normal "disconnected" mode.

HTH, Jens Suessmeyer.


http://www.sqlserver2005.de

|||

Thanks for the suggestion but of cource and i do call the update method. As I told you I can confirm that the records have been inserted.

The point is that I cannot see the records when I close the project

|||Why do you think you got a confirmation ?

Monday, March 12, 2012

I only get the first character of the field returned .. what am i doing wrong ?

here is my business/data object for some reason I only get the first character back, say value is Charlie, I only get C

 
public string GetUserName(long UserId) {try {string userName; DiscussionDB data =new DiscussionDB(); List paramlist =new List(); paramlist.Add(data.CreateParameter("@.UserId", UserId)); paramlist.Add(data.CreateParameter("@.UserName","", ParameterDirection.Output, DbType.String, 20)); data.ExecuteNonQuery("dbo.Discussion_User_Name",ref paramlist); userName = paramlist[1].Value.ToString();return userName; }catch {throw; } }ALTER PROCEDURE [dbo].[Discussion_User_Name]@.UserId bigint,@.UserName varchar(20) outputASSET NOCOUNT ONSET @.UserName = (Select [Name] from Discussion_Member WHERE UserID = @.UserID)if (@.UserNameis null or @.UserName ='')BEGIN SET @.UserName = (Select UserName from Membership_User WHERE UserID = @.UserID)END

hello,

It does not seem that thre is anything wrong with the code.

Have you checked the size of the columns "Name" and "UserName" in Discussion_Member and/or Membership_User ?

hope this helps?

regards,

g

|||

If you run the stored procedure using the sql server tools, does it return the correct result?

|||

yes when I run the SP in MS sever 2005 studio, I get the full field ... e.g Charlie

|||

You need to set the size of @.UserName, the default is 1. There's a size property toIDbDataParameter that you need to set (it looks like your DiscussionDB is wrapping IDbDataParameter and some other stuff)

|||

I tried wording your suggestion in my code by I can't seem to figure it out

I was thinking that the 20in the code below was giving the size

paramlist.Add(data.CreateParameter("@.UserName","", ParameterDirection.Output, DbType.String, 20));

|||

I thought I got this working but I was wrong

I am still having this issue, here is my last code

public string GetUserName(long UserId) {try {string userName; DiscussionDB data =new DiscussionDB(); List paramlist =new List(); paramlist.Add(data.CreateParameter("@.UserId", UserId)); paramlist.Add(data.CreateParameter("@.UserName","", ParameterDirection.Output, DbType.String, 15)); paramlist[1].Size = 15; data.ExecuteNonQuery("dbo.Discussion_User_Name_Fetch",ref paramlist); userName = paramlist[1].Value.ToString();return userName; }catch {throw; } }