Pomoć oko koda

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Posudbe : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
gvPosudbe.DataSource = null;
gvPosudbe.DataBind();

    }
}
protected void btnPosudi_Click(object sender, EventArgs e)
{
    int index = gvPosudbe.SelectedIndex;
    if(index!=-1)
    {
    //Primarni ključ 
    DataKey key = gvPosudbe.DataKeys[index];
    //Deklaracija skalarne varijable
    int @idPosudbe = (int)key.Value;

    //Kreiram Connection objekt
    string connString = ConfigurationManager.ConnectionStrings["VideotekaConnectionString"].ConnectionString;

    SqlConnection conn = new SqlConnection(connString);

    //Kreiram DataAdapter
    SqlDataAdapter adapter = new SqlDataAdapter();

    try
    {
        conn.Open();

        //Kreiranje naredbe SELECT
        adapter.SelectCommand = new SqlCommand("SELECT * FROM [Posudbe] ", conn);
        //Kreiranje INSERT, UPDATE i DELETE
        adapter.InsertCommand = new SqlCommand("INSERT INTO [Posudbe] ([idPosudbe], [idClana], [idNaslova], [Datum_posudbe], [Vraceno]) VALUES (@idPosudbe, @idClana, @idNaslova, @Datum_posudbe, @Vraceno)", conn);
        adapter.UpdateCommand = new SqlCommand("UPDATE [Posudbe] SET [idPosudbe] = @idPosudbe, [idClana] = @idClana, [idNaslova] = @idNaslova, [Datum_posudbe] = @Datum_posudbe, [Vraceno] = @Vraceno WHERE [idPosudbe] = @idPosudbe ", conn);
        adapter.DeleteCommand = new SqlCommand("DELETE FROM Posudbe WHERE idPosudbe=@idPosudbe", conn);

        //Kreiram Dataset objekt i DataTable objekt
        DataSet ds = new DataSet("Posudbe");
        DataTable dt = new DataTable("Posudbe");

        //Kreiram Sql parametar objekte
        SqlParameter param = new SqlParameter();

        param.ParameterName = "@idPosudbe";
        param.DbType = DbType.Int32;
        param.Direction = ParameterDirection.Input;
        param.Value = int.Parse(gvPosudbe.DataKeys[index]);

        param.ParameterName = "@idClana";
        param.DbType = DbType.Int32;
        param.Direction = ParameterDirection.Input;
        param.Value = "idClana";

        param.ParameterName = "@idNaslova";
        param.DbType = DbType.Int32;
        param.Direction = ParameterDirection.Input;
        param.Value = "idNaslova";


        //Definiram kolone tablice

        dt.Columns.Add("idPosudbe", typeof(string));
        dt.Columns.Add("idClana", typeof(string));
        dt.Columns.Add("idNaslova", typeof(string));
        dt.Columns.Add("Datum_posudbe", typeof(string));
        dt.Columns.Add("Vraceno", typeof(string));

        //Dodajem jedan redak tablice

        DataRow row = dt.NewRow();
        row["idPosudbe"] = "1";
        row["idClana"] = "gvClanovi.Rows[gvClanovi.SelectedIndex].Cells[1].Text";
        row["idNaslova"] = "gvNaslovi.Rows[gvNaslovi.SelectedIndex].Cells[2].Text";
        row["Datum_posudbe"] = "DateTime.Now.ToShortDateString()";
        row["Vraceno"] = "NE";
        dt.Rows.Add(row);
        //Tablicu dodajem DataSetu

        ds.Tables.Add(dt);

        int brojRedaka = adapter.Update(ds, "Posudbe");
    }
    catch (SqlException sqlEx)
    {
        Response.Write(sqlEx.Message);
    }
    finally
    {



        conn.Close();
        adapter.Dispose();
    }
}
}

Zašto ne radi?

Vidio sam “partial class”.
Pa provjerio šta je to.

Zvući mi malo previše opasno, kao da je došlo od Microsofta:)

Možda je u tome problem. Long shoot:)


Copyright © 2020 WM Forum - AboutContact - Sponsored by: Mydataknox & Webmaster.Ninja