Reputation: 37
I am working with VS 2017 for the first time.
I am trying to insert some values into a database. I already made the connection (checked with select statement) with the database, but now I am stuck in the insert portion.
I have a SqlDataSource
defined as:
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString=" <%$ ConnectionStrings:Sphinxx_Conn %>"
ProviderName="<%$ ConnectionStrings:Sphinxx_Conn.ProviderName %>"
InsertCommand="INSERT INTO "DEMO" ("ID", "NAME") VALUES (:ID, :NAME)">
<InsertParameters>
<asp:Parameter Name="ID" Type="String" />
<asp:Parameter Name="NAME" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</div>
Now the following snippet:
SqlDataSource1.InsertParameters["ID"].DefaultValue = '1'
SqlDataSource1.InsertParameters["NAME"].DefaultValue = 'John'
Underlines the 'SqlDataSource1.InsertParameters' part and shows an error:
Property access must assign to the property or use its value.
What exactly am I doing wrong?
Upvotes: 0
Views: 111
Reputation: 1796
There are 2 errors within your Code Snippet of assigning values.
char
value instead of string
, replace single quoted '
values with double quotes ". Instead of '1'
do this "1"
same with John too.;
to terminate your statement, so put semicolons in the end of your statements.Upvotes: 0
Reputation: 767
You are passing invalid data because you are using single quotes, use double quotes instead:
SqlDataSource1.InsertParameters["ID"].DefaultValue = "1";
SqlDataSource1.InsertParameters["NAME"].DefaultValue = "John";
On the side note, if you started working and getting to know web development with Visual Studio, i recommend you to look at MVC. Web Forms are old tech that is no longer supported.
Upvotes: 2