niketakapoor 0 Newbie Poster

hello everyone still now i m working in c# window application and now im working in asp.net
i made a same form and same coding in window application but this code is not working in asp.net...
i want to do here is:
member_id textbox
when i put some data in textbox i show the data in the label as(how many books a person have..)
my code is:

SqlConnection cs = new SqlConnection("Data Source=IRIS-CSG-174;Initial Catalog=library_system;Integrated Security=True");
cs.Open();
SqlCommand cmd = new SqlCommand("SELECT COUNT(1) as member_id FROM lib_issue_details WHERE member_id='" +TxtboxmemberId.Text + "'", cs);

SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
DataSet ds = new DataSet();
da.Fill(ds, "lib_issue_details");

Label2.DataBindings.Clear();
Label2.DataBindings.Add(new Binding("text", ds, "lib_issue_details.member_id"));

my last two lines of databinding is not working..
plzz help me regarding my code and correct it

niketakapoor 0 Newbie Poster

in the search form by display button records are displayed from database....but i wnt to change the header text of data grid column like member_id as memberID....
how can i do it
as i m tring

datagridview.column[1].headerText="memberID"

it shows error of indexes of collection so what code i will use to change the header text....!!!!

niketakapoor 0 Newbie Poster

exception occur i my code is:
Violation of PRIMARY KEY constraint 'PK__lib_book__1ADC427003317E3D'. Cannot insert duplicate key in object 'dbo.lib_book_details'.
The statement has been terminated.

SqlConnection cs = new SqlConnection("Data Source=IRIS-CSG-174;Initial Catalog=library_system;Integrated Security=True");
            SqlDataAdapter da = new SqlDataAdapter();
            da.UpdateCommand = new SqlCommand("Update Lib_book_details set book_tag_id=@book_tag_id,book_name=@book_name,book_author_name=@book_author_name where book_category_id=@book_category_id", cs);
            da.UpdateCommand.Parameters.Add("@book_tag_id", SqlDbType.Int).Value = textBox1.Text;
            da.UpdateCommand.Parameters.Add("@book_name", SqlDbType.VarChar).Value = textBox2.Text;
            da.UpdateCommand.Parameters.Add("@book_category_id", SqlDbType.Int).Value = Convert.ToInt32(comboBox1.SelectedValue);
            da.UpdateCommand.Parameters.Add("@book_author_name", SqlDbType.VarChar).Value = textBox3.Text;
            cs.Open();
            MessageBox.Show("new book updated!");
            da.UpdateCommand.ExecuteNonQuery();
            cs.Close();
niketakapoor 0 Newbie Poster

Book_Return_form
Book_tag_id=textbox1
Member_id=textbox2
Book_return_on=textbox3
Book_due_date=textbox4
Fine=textbox5
In this form when I put book-tag_id the rest items come automatically a/c to database and I hv done all till textbox4(book_due_date).
Now problem is with fine(textbox5)
Fine is calculated acc to membership_type,there are three types of membership silver,gold,platinum
Fines are:silver=30,gold=20,platinum=30 so the calculated fine a/c membership come on text box
As (return_date-due_date)-30,20or10 ,till now I m working with dataadapter but now I want to work with dll class,I make a dll class and know how to add reference to project but I m missing smthing in my code while I m making class.(so help me in code)
I made a stored procedure with name(member_details)colums:tag_id,member_id,membership_type_id,membership_type(eg:909,5,1,silver)
My full code for dll class is:

Firstly,I make class name transcation_details
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;


namespace selectfinedetails
{
public class TransactionService
{

SqlConnection cs;


private void OpenConnection()
{

cs = new SqlConnection();
cs.ConnectionString = "Data Source=IRIS-CSG-174;Initial Catalog=library_system;Integrated Security=True";

cs.Open();

}
public membership_details calculatefine()
{
OpenConnection();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Exec member_fine_detail";
SqlParameter prm1=new SqlParameter("member_id", SqlDbType.Int);
cmd.Parameters.Add(prm1);

SqlParameter prm2=new SqlParameter("fine_per_day", SqlDbType.Int);
cmd.Parameters.Add(prm2);
prm1.Direction=ParameterDirection.Output;
prm2.Direction=ParameterDirection.ReturnValue;

membership_details myObjec = new membership_details();
cmd.ExecuteNonQuery();
SqlDataReader sdr = cmd.ExecuteReader();
myObjec.fine_per_day = //cmd.CommandText;(this is error)

return myObjec;

but I this above code I m missing smthing,as this code will result nthing as to calculate fine with member_id…so what code I will add in it and in as calculatefine()

niketakapoor 0 Newbie Poster

Book_Return_form
Book_tag_id=textbox1
Member_id=textbox2
Book_return_on=textbox3
Book_due_date=textbox4
Fine=textbox5
In this form when I put book-tag_id the rest items come automatically a/c to database and I hv done all till textbox4(book_due_date).
Now problem is with fine(textbox5)
Fine is calculated acc to membership_type,there are three types of membership silver,gold,platinum
Fines are:silver=30,gold=20,platinum=30 so the calculated fine a/c membership come on text box

As (return_date-due_date)-30,20or10 ,till now I m working with dataadapter but now I want to work with dll class,I make a dll class and know how to add reference to project but I m missing smthing in my code while I m making class.(so help me in code)
I made a stored procedure with name(member_details)colums:tag_id,member_id,membership_type_id,membership_type(eg:909,5,1,silver)
My full code for dll class is:
Firstly,I make class name transcation_details

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;


namespace selectfinedetails
{
    public class TransactionService
    {

        SqlConnection cs;
       

        private void OpenConnection()
        {

            cs = new SqlConnection();
            cs.ConnectionString = "Data Source=IRIS-CSG-174;Initial Catalog=library_system;Integrated Security=True";

            cs.Open();
  
        }
        public membership_details calculatefine()
        {
            OpenConnection();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Exec member_fine_detail";
          SqlParameter prm1=new SqlParameter("member_id", SqlDbType.Int);
            cmd.Parameters.Add(prm1);
         
            SqlParameter prm2=new SqlParameter("fine_per_day", SqlDbType.Int);
            cmd.Parameters.Add(prm2);
            prm1.Direction=ParameterDirection.Output;
            prm2.Direction=ParameterDirection.ReturnValue;
        
             membership_details myObjec = new membership_details();
            cmd.ExecuteNonQuery();
             SqlDataReader sdr = cmd.ExecuteReader();
             myObjec.fine_per_day = //cmd.CommandText;(this is error)
             
            return myObjec;

but I this above code I m missing smthing,as this code will result nthing as to calculate fine with member_id…so what code I will add in it and in as calculatefine()

niketakapoor 0 Newbie Poster

m trying to make dll class but in m facing errors in it plzzz help me to resolve the...i really need help!!!
my full code is:-

namespace selectfinedetails
{
public class TransactionService
{

SqlConnection cs;


private void OpenConnection()
{

cs = new SqlConnection();
cs.ConnectionString = "Data Source=IRIS-CSG-174;Initial Catalog=library_system;Integrated Security=True";

cs.Open();
}
public void calculatefine()
{
OpenConnection();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Exec member_fine_detail";
cmd.Parameters.Add(new SqlParameter("member_id", SqlDbType.Int));

SqlDataReader sdr = cmd.ExecuteReader();
cmd.ExecuteNonQuery();
{
public class member_details
{
private void details()
{
member_details obj = new member_details();
SqlCommand cmd = new SqlCommand();
obj.member_id =cmd.ExecuteReader();
obj.fine_per_day=cmd.ExecuteReader();
return obj=cmd.ExecuteScalar();

in member_details class member_id and fine_per day need to be define..how to define them...

niketakapoor 0 Newbie Poster

i make a stored procedure create proc member_finedetails as
select lib_member_details.member_id,lib_member_details.membershiptype_id,membership_desc,fine_per_day
FROM lib_member_details INNER JOIN membership_details
ON lib_member_details.membershiptype_id=membership_details.membershiptype_id

now iwnt to work on it by making dll class...i m confused how to make class of it.plzzzzzzz help me to make dll class of this stored proc...

niketakapoor 0 Newbie Poster

i m working on a project and still now i m working with data adapter but now i have to work in dll..

tag_id=textbox
member_id=textbox
book_retun date=textbox
due_date=textbox
fine=textbox
as i put tag_id in text box all textbox get automatically filled...
for fine it is related to membership_desc silver=10 gold=20 platinum=30per day
i make a stored procedue
create proc member_finedetails as
select lib_member_details.member_id,lib_member_details.membershiptype_id,membership_desc,fine_per_day
FROM lib_member_details INNER JOIN membership_details
ON lib_member_details.membershiptype_id=membership_details.membershiptype_id

now how to do all this using dll class..
how to define related data in dll class...
and give refrence of it to whom???? so i get the calculated fine according to member_id filled in textbox
eg,
member_id=5
membershiptype_id=3
membership_desc=gold
fine_per_day=20
return_date-due_date)*fine acc to membership_id or desc...

niketakapoor 0 Newbie Poster

Hello...!!!
help me if u can..Thanks in advance!!!

database table=issue_details in which columns are issue_id is identity,book_tag_id,member_id,book_issue_on.due_date

database table=return_details colums are return_id identity,issue_id,book_returned_on,fine_per_day

database=membership_details columns are membership_id,membership_desc(gold,silver,platinum)


Now my return form is:book_tag_id=textbox1
member_id=textbox2
Issue_date=textbox3
returndate=textbox4
fine=textbox5


textbox5:-fine
membership_desc=silver,gold,platinum
fine_per_day for silver=30
gold=20
platinum=10
now what code i will write soo that when tag_id is filled in text_box 1
the fine according to membership_desc and return and due date...calculated fine get displayed automatically in text box 5
(due_date-returndate)*20 or 10 or 30
i think if else is used but how to add code in c# so calculated fine is displayed in text box!!

niketakapoor 0 Newbie Poster

Hello...!!!
help me if u can..Thanks in advance!!!

database table=issue_details in which columns are issue_id is identity,book_tag_id,member_id,book_issue_on.due_date

database table=return_details colums are return_id identity,issue_id,book_returned_on,fine_per_day

database=membership_details columns are membership_id,membership_desc(gold,silver,platinum)

as u see in return databasetable return_id is identity but issue_id is int
Now my return form is:book_tag_id=textbox1
member_id=textbox2
Issue_date=textbox3
returndate=textbox4
fine=textbox5
in the form the member_id,issue_date is fetched from book_tag_id so these textbox2&3 are readonly.
return_date is date of system.
see my code...this all is working fine.....
but problem is with issue_id in return table...as this is fetched from tag_id or from issue_database

da.InsertCommand = new SqlCommand("Insert` into book_return_details Values(@book_issue_id,@book_returned_on,@late_fine)", cs);

da.InsertCommand.Parameters.Add("@book_issue_id", SqlDbType.Int).Value =???????
what i should add in ??? so that issue_id automatically saved in database!!!!!!!!!!!!

niketakapoor 0 Newbie Poster

membership desc=silver,gold,platinum
fine_per day=30,20,10
from book_due date and returned_date as number of days in which fine is added to get the fine............
how this can b done in c#
i think the calculation is done as(book_due_date)-(book_returned_on)*30 or 20 or10
how to do all this in c# to get fine in textbox

niketakapoor 0 Newbie Poster

hello everyone help me in this code
database table membership_details
membership_id,membership_desc,fine_per day,membership_fees

return table
book return id identity,book_issue_id int,book_late_fine

issue table
issue_id identity,book_tag_id


da.InsertCommand = new SqlCommand("Insert` into book_return_details Values(@issue_id,@book_returned_on,@late_fine)", cs);
            //da.InsertCommand.Parameters.Add("@book_issue_id", SqlDbType.Int).Value = ?????????????


what code i will insert in ???? so that issue id get saved in database...
the issue_id can be get from tag_id i think....bt how to write code to get it!!!!!

niketakapoor 0 Newbie Poster

thanks..hope it will work!!

niketakapoor 0 Newbie Poster

thanks...will due date comes automatically in read only textbox???

niketakapoor 0 Newbie Poster

As i click update button data is updated but all the data in the table get with it....(same data in whole table)
suggest me what i doing WRONG in it....

private void btnUpdate_Click(object sender, EventArgs e)
        {
            SqlConnection cs = new SqlConnection("Data Source=IRIS-CSG-174;Initial Catalog=library_system;Integrated Security=True");
            SqlDataAdapter da = new SqlDataAdapter();
            da.UpdateCommand = new SqlCommand("Update Lib_member_details set member_name=@member_name,member_address=@member_address,member_contact_number=@member_contact_number,member_email_id=@member_email_id,member_password=@member_password,membershiptype_id=@membershiptype_id", cs);
            da.UpdateCommand.Parameters.Add("@member_name", SqlDbType.VarChar).Value = textBox2.Text;
            da.UpdateCommand.Parameters.Add("@member_address", SqlDbType.VarChar).Value = textBox3.Text;
            da.UpdateCommand.Parameters.Add("@member_contact_number", SqlDbType.Int).Value = Convert.ToInt32(textBox4.Text);
            da.UpdateCommand.Parameters.Add("@member_email_id", SqlDbType.VarChar).Value = textBox5.Text;
            da.UpdateCommand.Parameters.Add("@member_password", SqlDbType.Int).Value = Convert.ToInt32(textBox6.Text);
            da.UpdateCommand.Parameters.Add("@membershiptype_id", SqlDbType.Int).Value = Convert.ToInt32(comboBox1.SelectedValue);
            cs.Open();
            MessageBox.Show("member data updated!");
            da.UpdateCommand.ExecuteNonQuery();
            cs.Close();
niketakapoor 0 Newbie Poster
private void Form_AddMember_Load(object sender, EventArgs e)
        {
            da.SelectCommand = new SqlCommand("SELECT * from dbo.membership_details", cs);
            DataSet ds = new DataSet();
            da.Fill(ds, "membership_details");
            comboBox1.DataSource = ds.Tables["membership_details"];
            comboBox1.DisplayMember = "membership_desc";
            comboBox1.ValueMember = "membershiptype_id";
             da.SelectCommand = new SqlCommand("select membership_fees from dbo.membership_details where membership_desc='" + comboBox1.SelectedValue + "'", cs);
                    SqlCommand cmd = new SqlCommand("select membership_fees from dbo.membership_details where membership_desc='" + comboBox1.SelectedValue + "'", cs);
                    da.Fill(ds, "membership_details.membership_fees");
                    textBox7.DataBindings.Add(new Binding("Text", ds, "membership_details.membership_fees"));

private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            da.SelectCommand = new SqlCommand("select membership_fees from dbo.membership_details where membership_desc='" + comboBox1.SelectedValue.ToString()+ "'", cs);
            da.Fill(ds, "membership_details.membership_fees");
            textBox7.Text = comboBox1.SelectedValue.ToString();

combobox1=membership_desc
textbox7=fees(automatically)
Suggest me what i m missing here....THe data is fixed it is not changing as i change values of combobox...

niketakapoor 0 Newbie Poster

Thanks i guess it works..
Hope it will not give any exception

niketakapoor 0 Newbie Poster

okk...thanks but i m not taking the current date...see my code line above ???...
actually i tried everthing but i m not getting it....!!!!

niketakapoor 0 Newbie Poster

thanks for the reply..!!!
can u plzz help me in the above code,,,as where to add this code

niketakapoor 0 Newbie Poster

i want due date comes automatically as by adding after 15 days from date of issue.................

private void btnIssueBk_Click(object sender, EventArgs e)
{

SqlConnection cs = new SqlConnection("Data Source=IRIS-CSG-174;Initial Catalog=library_system;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter();
cs.Open();
da.InsertCommand = new SqlCommand("Insert into Lib_issue_details Values(@book_tag_id,@member_id,@book_issue_on,@book_due_date)", cs);
da.InsertCommand.Parameters.Add("@book_tag_id", SqlDbType.VarChar).Value = textBox2.Text;
[B]da.InsertCommand.Parameters.Add("@member_id", SqlDbType.VarChar).Value = textBox3.Text;

da.InsertCommand.Parameters.Add("@book_issue_on", SqlDbType.DateTime).Value = Convert.ToDateTime(textBox4.Text);
da.InsertCommand.Parameters.Add("@book_due_date", SqlDbType.DateTime).Value=??????????????????????????????????
[/B]
DataSet ds = new DataSet();
DataTable dt = new DataTable();
//textBox4.Text = dt.AddDays(15).ToString();
textBox5.DataBindings.Add(new Binding("Text", ds, "issue_details.due_date"));
da.InsertCommand.ExecuteNonQuery();

what code i add to get due date automatically........... suggest me the correct code for it!!!!!!!!!!!!

niketakapoor 0 Newbie Poster

i have combobox in which membership_desc=gold,silver,platinum is displayed
and have textbox in which i want that fees displayed automatically in it
as
gold=100
silver=200
platinum=300

form_load();
combobox1.datasource=ds.tables["membership_details"];
combobox1.displaymember="membership_type";
combobox1.valuemember="membership_id";

combobox1_selected_index_chanded();
da.selectcommand=neew sqlcommand("select membership fees from membership_details where membership_desc='"+combobox1.selectedvalue+"'",cs);
textbox7.text=??????????????????????????????????????????

as i do binding of text box it show ERROR that binding is done in two contexts
so how i will show the data in text box.....
......thanks in advance....

niketakapoor 0 Newbie Poster

hello everyone
i have a "text box" in which i have to put" member_id" and fetch records as number of books issued to that particular "member_id"....
database tables are lib_member_details and issue_detIails...
issue_details=tag_id,member_id,book_issue_on,due date...
suggest me the code for this problem in c# with sql
also help me that can i fetch the"""due_date""" with book_issue_on as if i put as maximum days 15 then automatically date will come out related to book _issue_on..... Help me plzzz i want to complete my project...!!!!

niketakapoor 0 Newbie Poster

hello everyone!!
i m new to c# and making project on c# window application.I learned a lot from daniweb but now i m stuck in one thing help me to resolve the problem.
database table lib_book_details in which column are tag_id,book_name,author_name.
Now i want to make a search form in which i add tag_id in textbox and the rest data appears as per my search.
Thanks in advance..