SqlDataSource InsertParameters C# .Net 2.0

Hello Experts,

I am using C# and ASP.Net 2.0 to store values in a database. I am using a SqlDataSource to connect to my database. I am able to retrieve data however I have problems storing data. I have the datasource set to use datasets.

The problem I am facing is that to store an entry I need two parameters of type Guid. However when I try to insertParameters using Guids I get an error saying that I need to use Strings. However when I use Strings I get an exception when inserting saying that I need a uniqueIdentifier and not a String.

Please give me advice on how to store a new entry or to set the parameters correctly. I can't use databinding for this task.

Thank You,
Ohmstor

Below is some code that I use:
           
            Guid schedulerId = new Guid();
            Guid userId= new Guid();
       
            SqlDataSource2.InsertParameters["schedulerID"] = schedulerId;
            SqlDataSource2.InsertParameters["userID"] = userId;
           
            SqlDataSource2.Insert();
--------------------------------------
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:MyLocalSQLServer %>"
        DeleteCommand="DELETE FROM [scheduler] WHERE [schedulerID] = @schedulerID" InsertCommand="INSERT INTO [scheduler] ([schedulerID], [userID]) VALUES (@schedulerID, @userID)"
        ProviderName="<%$ ConnectionStrings:MyLocalSQLServer.ProviderName %>" SelectCommand="SELECT [schedulerID], [userID] FROM [scheduler]"
        UpdateCommand="UPDATE [scheduler] SET [userID] = @userID WHERE [schedulerID] = @schedulerID">
        <DeleteParameters>
            <asp:Parameter Name="schedulerID" Type=Object />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="userID" Type=Object />
            <asp:Parameter Name="schedulerID" Type=Object />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="schedulerID" Type=Object />
            <asp:Parameter Name="userID" Type=Object />
        </InsertParameters>
    </asp:SqlDataSource>
ohmstorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aki4uCommented:
You can NOT change uniqueIdentifier!
What type is userID?
0
aki4uCommented:
in your database ... I see you are using here an Object type for both??? Any reason for this?
0
aki4uCommented:
Sorry, I thought you are trying to change the Identity...never mind
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

ohmstorAuthor Commented:
both the userId and the schedulerId are uniqueIdentifers.

I am using the Object as a Type because I couldn't find Guid or UniqueIdentifer and it seems to be the closest match.
0
bsdotnetCommented:
you can use NEWID() as default value for UserID and SchedulerID in your SQL table design.

NEWID() function to will give you a globally unique ID (GUID).

"Guid schedulerId = new Guid();" and "Guid userId= new Guid();" give you "00000000-0000-0000-0000-000000000000"



0
aki4uCommented:
you ca use that or from your code behind, like this:
string strGuid = Guid.NewGuid().ToString();

so, to get new guid use: Guid.NewGuid().ToString()

also, I would change object type you have to string.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ohmstorAuthor Commented:
Thanx a lot! When I changed the object type to string in the SqlDataSource it worked. Can you guys explain why though? Also thanx for providing the newguid function.
0
ohmstorAuthor Commented:
How can you add assisted answers?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.