Robię taką rzecz pierwszy raz i niestety nie udało mi się, wyskoczył błąd
Ktoś może mnie nakierować co poprawić? niestety jestem poniekąd zielony byłem prawie pewny że mi się uda niestety byłem w błędzie. Co zrobiłem źle?
Błąd serwera w aplikacji '/'.
Incorrect syntax near ')'.
Opis: Podczas wykonywania bieżącego żądania sieci Web wystąpił nieobsługiwany wyjątek. Aby uzyskać dodatkowe informacje o błędzie i miejscu jego występowania w kodzie, przejrzyj ślad stosu.
Szczegóły wyjątku: System.Data.SqlClient.SqlException: Incorrect syntax near ')'.
Błąd źródła:
Wiersz 114: SqlCommand cmdd = new SqlCommand(sqll, conn);
Wiersz 115:
Wiersz 116: cmdd.ExecuteNonQuery();
Wiersz 117: }
Wiersz 118:
Plik źródłowy: c:\Users\Admin\Documents\Visual Studio 2015\WebSites\Shop\Administrator\AddProducts.aspx.cs Wiersz: 116
Ślad stosu:
''[SqlException (0x80131904): Incorrect syntax near ')'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +2442126 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction) +5736904
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +628
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +3731
System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite) +940
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) +272
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +280
Administrator_AddProducts.btnAdd_Click(Object sender, EventArgs e) in c:\Users\Admin\Documents\Visual Studio 2015\WebSites\Shop\Administrator\AddProducts.aspx.cs:116
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9692746
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3562
-------------------------------------------------------------------------------------------''
KOD STRONY
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="AddProducts.aspx.cs" Inherits="Administrator_AddProducts" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<table class="addproducts" style="width: 100%">
<tr>
<td align="center" colspan="3">Dodaj przedmiot do sklepu
<asp:Button ID="btnSearch" runat="server" Text="Szukaj" OnClick="btnSearch_Click" />
<asp:TextBox ID="tb_Search" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label1" runat="server" Text="Numer ID Produtku:"></asp:Label>
</td>
<td style="width: 214px">
<asp:TextBox ID="tb_product_id" runat="server" style="width: 100%"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label2" runat="server" Text="Nazwa Produktu:"></asp:Label>
</td>
<td style="width: 214px">
<asp:TextBox ID="tb_product_name" runat="server" style="width: 100%"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label3" runat="server" Text="Opis Produtku: (do 1000 znaków)"></asp:Label>
</td>
<td style="width: 214px">
<asp:TextBox ID="tb_product_description" runat="server" style="width: 100%" TextMode="MultiLine"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label4" runat="server" Text="Krótki Opis Produktu: (do 100 znaków)"></asp:Label>
</td>
<td style="width: 214px">
<asp:TextBox ID="tb_product_short_description" runat="server" style="width: 100%" TextMode="MultiLine"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label5" runat="server" Text="Cena Produktu:"></asp:Label>
</td>
<td style="width: 214px">
<asp:TextBox ID="tb_unit_price" runat="server" style="width: 100%"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label6" runat="server" Text="Cena Detaliczna Produktu:"></asp:Label>
</td>
<td style="width: 214px">
<asp:TextBox ID="tb_MSRP" runat="server" style="width: 100%"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label7" runat="server" Text="Dostępne Rozmiary:"></asp:Label>
</td>
<td style="width: 214px">
<asp:Button ID="btnButy" runat="server" OnClick="btnButy_Click" Text="Buty" />
<asp:Button ID="btnKoszulki" runat="server" OnClick="btnKoszulki_Click" Text="Koszulki" />
<asp:Button ID="btnSpodnie" runat="server" OnClick="btnSpodnie_Click" Text="Spodnie" />
<asp:DropDownList ID="ddlAvailableSize" runat="server">
<asp:ListItem Value="1">Buty</asp:ListItem>
<asp:ListItem Value="2">Koszulki</asp:ListItem>
<asp:ListItem Value="3">Spodnie</asp:ListItem>
</asp:DropDownList>
<asp:CheckBoxList ID="cbBoots" runat="server" style="margin-top: 0px" DataValueField = "available_size">
<asp:ListItem Value="b32">32</asp:ListItem>
<asp:ListItem Value="b34">34</asp:ListItem>
<asp:ListItem Value="b36">36</asp:ListItem>
<asp:ListItem Value="b38">38</asp:ListItem>
<asp:ListItem Value="b40">40</asp:ListItem>
</asp:CheckBoxList>
<asp:CheckBoxList ID="cbShirt" runat="server" DataValueField = "available_size">
<asp:ListItem Value="s36">36</asp:ListItem>
<asp:ListItem Value="s37">37</asp:ListItem>
<asp:ListItem Value="s38">38</asp:ListItem>
<asp:ListItem Value="s39">39</asp:ListItem>
<asp:ListItem Value="s40">40</asp:ListItem>
</asp:CheckBoxList>
<asp:CheckBoxList ID="cbTrausers" runat="server" DataValueField = "available_size">
<asp:ListItem Value="t40">40</asp:ListItem>
<asp:ListItem Value="t42">42</asp:ListItem>
<asp:ListItem Value="t44">44</asp:ListItem>
<asp:ListItem Value="t46">46</asp:ListItem>
</asp:CheckBoxList>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label8" runat="server" Text="Dostępne Kolory:"></asp:Label>
</td>
<td style="width: 214px">
<asp:CheckBoxList ID="cbl_color" runat="server" Width="113px">
<asp:ListItem>Czerwony</asp:ListItem>
<asp:ListItem>Niebieski</asp:ListItem>
<asp:ListItem>Czarny</asp:ListItem>
<asp:ListItem>Biały</asp:ListItem>
<asp:ListItem>Zielony</asp:ListItem>
</asp:CheckBoxList>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label9" runat="server" Text="Waga Produktu:"></asp:Label>
</td>
<td style="width: 214px">
<asp:TextBox ID="tb_unit_weight" runat="server" style="width: 100%"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label10" runat="server" Text="Rozmiar Produktu:"></asp:Label>
</td>
<td style="width: 214px">
<asp:DropDownList ID="ddl_size" runat="server">
<asp:ListItem>XXL</asp:ListItem>
<asp:ListItem>XL</asp:ListItem>
<asp:ListItem>L</asp:ListItem>
<asp:ListItem>M</asp:ListItem>
<asp:ListItem>S</asp:ListItem>
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label11" runat="server" Text="Dostępność Produktu:"></asp:Label>
</td>
<td style="width: 214px">
<asp:DropDownList ID="ddl_product_available" runat="server">
<asp:ListItem Value="Full">Pełno</asp:ListItem>
<asp:ListItem Value="ALot">Dużo</asp:ListItem>
<asp:ListItem Value="Medium">Średnio</asp:ListItem>
<asp:ListItem Value="AlmostEmpty">Na Końcówce</asp:ListItem>
<asp:ListItem Value="Empty">Brak</asp:ListItem>
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label12" runat="server" Text="Dostępna Zniżka Produktu:"></asp:Label>
</td>
<td style="width: 214px">
<asp:DropDownList ID="ddl_discount_available" runat="server">
<asp:ListItem Value="true">Tak</asp:ListItem>
<asp:ListItem Value="false">Nie</asp:ListItem>
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label17" runat="server" Text="Zniżka Produktu:"></asp:Label>
</td>
<td style="width: 214px">
<asp:DropDownList ID="ddl_discount" runat="server">
<asp:ListItem>10%</asp:ListItem>
<asp:ListItem>20%</asp:ListItem>
<asp:ListItem>30%</asp:ListItem>
<asp:ListItem>40%</asp:ListItem>
<asp:ListItem>50%</asp:ListItem>
<asp:ListItem>60%</asp:ListItem>
<asp:ListItem>70%</asp:ListItem>
<asp:ListItem>80%</asp:ListItem>
<asp:ListItem>90%</asp:ListItem>
<asp:ListItem>100%</asp:ListItem>
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label13" runat="server" Text="Zdjęcie Produktu:"></asp:Label>
</td>
<td style="width: 214px">
<asp:DropDownList ID="ddl_picture_big" runat="server">
<asp:ListItem Value="Sandaly">Sandały</asp:ListItem>
<asp:ListItem>Koszulka</asp:ListItem>
<asp:ListItem Value="Jeansy">Jeansy</asp:ListItem>
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label14" runat="server" Text="Małe Zdjęcie Produktu:"></asp:Label>
</td>
<td style="width: 214px">
<asp:DropDownList ID="ddl_picture_small" runat="server">
<asp:ListItem>Sandaly</asp:ListItem>
<asp:ListItem>Koszulka</asp:ListItem>
<asp:ListItem>Jeansy</asp:ListItem>
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label16" runat="server" Text="Dostawca Produktu:"></asp:Label>
</td>
<td style="width: 214px">
<asp:DropDownList ID="ddl_supplier_id" runat="server" DataSourceID="SqlDataSource1" DataTextField="suppliers_id" DataValueField="suppliers_id">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ShopConnectionStringSupplierToProducts %>" SelectCommand="SELECT [company_name], [suppliers_id] FROM [Suppliers]"></asp:SqlDataSource>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label15" runat="server" Text="Kategoria Produktu:"></asp:Label>
</td>
<td style="width: 214px">
<asp:DropDownList ID="ddl_category_id" runat="server" DataSourceID="SqlDataSource2" DataTextField="category_id" DataValueField="category_id">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ShopConnectionString %>" SelectCommand="SELECT [category_id], [category_name] FROM [Category]"></asp:SqlDataSource>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Label ID="Label18" runat="server" Text="Notatka:"></asp:Label>
</td>
<td style="width: 214px">
<asp:TextBox ID="tb_note" runat="server" style="width: 100%" TextMode="MultiLine"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td style="width: 193px">
<asp:Button ID="btnAdd" runat="server" Text="Dodaj" OnClick="btnAdd_Click" />
<asp:Button ID="btnDelete" runat="server" Text="Usuń" />
<asp:Button ID="btnEdit" runat="server" Text="Edytuj" />
</td>
<td style="width: 214px"> </td>
<td> </td>
</tr>
</table>
</asp:Content>
KOD TYLNI STRONY
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Administrator_AddProducts : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
cbBoots.Visible = false;
cbShirt.Visible = false;
cbTrausers.Visible = false;
ddlAvailableSize.Visible = false;
}
protected void ddlAvailableSize_TextChanged(object sender, EventArgs e)
{
switch (ddlAvailableSize.SelectedValue)
{
case "1":
cbShirt.Visible = false;
cbTrausers.Visible = false;
cbBoots.Visible = true;
break;
case "3":
cbBoots.Visible = false;
cbShirt.Visible = false;
cbTrausers.Visible = true;
break;
case "2":
cbBoots.Visible = false;
cbTrausers.Visible = false;
cbShirt.Visible = true;
break;
}
}
protected void btnButy_Click(object sender, EventArgs e)
{
cbShirt.Visible = false;
cbTrausers.Visible = false;
cbBoots.Visible = true;
}
protected void btnKoszulki_Click(object sender, EventArgs e)
{
cbBoots.Visible = false;
cbTrausers.Visible = false;
cbShirt.Visible = true;
}
protected void btnSpodnie_Click(object sender, EventArgs e)
{
cbBoots.Visible = false;
cbShirt.Visible = false;
cbTrausers.Visible = true;
}
protected void btnAdd_Click(object sender, EventArgs e)
{
string TextcbBoots = string.Empty;
string TextcbShirt = string.Empty;
string TextcbTrausers = string.Empty;
string Textcbl_color = string.Empty;
for (int i = 0; i < cbBoots.Items.Count; i++)
{
if (cbBoots.Items[i].Selected == true)
{
TextcbBoots = cbBoots.Items[i].Value.ToString() + ",";
}
}
for (int j = 0; j < cbShirt.Items.Count; j++)
{
if (cbShirt.Items[j].Selected == true)
{
TextcbShirt = cbShirt.Items[j].Value.ToString() + ",";
}
}
for (int k = 0; k < cbTrausers.Items.Count; k++)
{
if (cbTrausers.Items[k].Selected == true)
{
TextcbTrausers = cbTrausers.Items[k].Value.ToString() + ",";
}
}
for (int l = 0; l < cbl_color.Items.Count; l++)
{
if (cbl_color.Items[l].Selected == true)
{
Textcbl_color = cbl_color.Items[l].Value.ToString() + ",";
}
}
string[] AvailableSize = { };
SqlConnection conn = new SqlConnection(@"Data Source=ADMIN-KOMPUTER\SQL_KACPER;Initial Catalog=Shop;Integrated Security=True");
conn.Open();
string sqll = "INSERT INTO Products(product, product_name, product_description, product_short_description, unit_price, MSRP, available_size, available_color, unit_weight, size, product_available, discount_available, discount, picture_big, picture_small, supplier_id, category_id, note) VALUES ('" + tb_product_id.Text + "' , '" + tb_product_name.Text + "' , '" + tb_product_description.Text + "' , '" + tb_product_short_description.Text + "' , '" + tb_unit_price.Text + "' , '" + tb_MSRP.Text + "' , '" + TextcbBoots + TextcbShirt + TextcbTrausers + "' , '" + Textcbl_color + "' , '" + tb_unit_weight.Text + "' , '" + ddl_size.SelectedItem.Text + "' , '" + ddl_product_available.SelectedItem.Text + "' , '" + ddl_discount_available.SelectedItem.Text + "' , '" + ddl_discount.SelectedItem.Text + "' , '" + ddl_picture_big.SelectedItem.Text + "' , '" + ddl_picture_small.SelectedItem.Text + "' , '" + ddl_supplier_id.SelectedItem.Text + "' , '" + ddl_category_id.SelectedItem.Text + "' , '" + tb_note.Text + "' , )";
SqlCommand cmdd = new SqlCommand(sqll, conn);
cmdd.ExecuteNonQuery();
}
protected void btnSearch_Click(object sender, EventArgs e)
{
}
}