Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,434 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,348 people online right now. Registration is fast and FREE... Join Now!




Gridview problem

 
Reply to this topicStart new topic

Gridview problem

sulaiman_web
18 Aug, 2008 - 01:26 AM
Post #1

New D.I.C Head
*

Joined: 17 Aug, 2008
Posts: 5

Hi friends,

i am using Visual web developer to design the website. In my website i have a multiline textbox. i want to give 10 input values in the multiline textbox and display the database records in the gridview. But the last record only printed in the gridview. I have used 2 tables namely Sinmain and Tranship.can u clear my doubts? Thanx to u all.



csharp

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.Web.Configuration;
using System.Data.SqlClient;
using System.Text;
using System.Drawing;


public partial class TrackingDet : System.Web.UI.Page
{


//protected System.Web.UI.HtmlControls.HtmlGenericControl frame1;
//HtmlControl frame1 = (HtmlControl)this.FindControl("frame1");
//frame1.attr

protected void Page_Load(object sender, EventArgs e)
{

String strcnno = Session["username"].ToString(); ;
//cnno = cnno.Trim();
Char[] chDelims = new Char[] { '\n','\r' };
String[] cnnoarr = strcnno.Split(chDelims,StringSplitOptions.RemoveEmptyEntries);


//while (x < cnnoarr.Length )
//{

//String cnno = cnnoarr[0]; String cnno1 = cnnoarr[2];
//String cnno2 = cnnoarr[4];
//String cnno3 = cnnoarr[6]; String cnno4 = cnnoarr[8];
//String cnno5 = cnnoarr[10]; String cnno6 = cnnoarr[12];
//String cnno7 = cnnoarr[14]; String cnno8 = cnnoarr[16];
//String cnno9 = cnnoarr[18];
//while (i <= 10)
//{

foreach (String strArr in cnnoarr)
{

if (!IsPostBack)
{
int recCount = 0;
String StrCon = "Server=www.*******.com; DataBase=******; uid=******; pwd=*****;Asynchronous Processing=true";

SqlConnection Conn = new SqlConnection(StrCon);

SqlDataAdapter Dap = new SqlDataAdapter();
//SqlDataAdapter Dap1 = new SqlDataAdapter();


String StrSql = "SELECT Count(*) FROM firstflight.TRANSHIP" +
" WHERE (CNNO ='" + strArr + "') ";

DataSet ds = new DataSet();
//DataSet ds1 = new DataSet();
SqlCommand cmd1 = new SqlCommand(StrSql, Conn);

cmd1.Connection.Open();

recCount = (int)cmd1.ExecuteScalar();


if (recCount == 0)
{

String StrSqlS = "SELECT Count(*) FROM firstflight.SINMAIN" +
" WHERE (CNNO ='" + strArr + "')";
SqlCommand cmdS = new SqlCommand(StrSqlS, Conn);
cmd1.Connection.Close();
cmdS.Connection.Open();
recCount = (int)cmdS.ExecuteScalar();

String StrSqlS1 = "SELECT CNNO, CONVERT (varchar(20), BOOKDATE, 103) AS recddate, COUNTRY as destn, REFNO, DELDATE, DELTIME, SIGN, REMARKS FROM firstflight.SINMAIN" +
" WHERE (CNNO ='" + strArr + "')";

cmdS.Connection.Close();

SqlCommand cmdS1 = new SqlCommand(StrSqlS1, Conn);
cmd1.Connection.Close();
cmdS1.Connection.Open();
Dap.SelectCommand = cmdS1;
Dap.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
cmdS1.Connection.Close();

}

else
{

String StrSqlT = "SELECT CNNO, REFNO, CONVERT (varchar(20), RECDDATE, 103) AS RECDDATE, DESTN , DELDATE , DELTIME , SIGN, REMARKS FROM firstflight.TRANSHIP" +
" WHERE (CNNO ='" + strArr + "')";
SqlCommand cmdT = new SqlCommand(StrSqlT, Conn);
cmd1.Connection.Close();
cmdT.Connection.Open();
Dap.SelectCommand = cmdT;
Dap.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
cmdT.Connection.Close();

}

}


}

}
}

User is offlineProfile CardPM
+Quote Post

modi123_1
RE: Gridview Problem
18 Aug, 2008 - 08:06 AM
Post #2

D.I.C Addict
Group Icon

Joined: 12 Jun, 2008
Posts: 531



Thanked: 13 times
Dream Kudos: 100
My Contributions
Not to be a dick or anything, but you shouldn't put your company's database log in out to the world to see... that's pretty dumb.

Second, your problem is you are not not taking into account the multiple values in the text box - only the last one. What you need to do is either call the database for each line in the multi-line textbox and store that row that comes back into a temporary dataset until you are done with all ten, or collect all your rows, format them into a string like "(<value1>, <value2>, ...)" and have your stored procedure take in that string and run your select statement as

CODE

SELECT Count(*) FROM firstflight.TRANSHIP
WHERE (CNNO IN '<that string i told you to make>')



oh.. and never do a select * on production code.. that's just juvenile.

This post has been edited by modi123_1: 18 Aug, 2008 - 08:06 AM
User is offlineProfile CardPM
+Quote Post

sulaiman_web
RE: Gridview Problem
19 Aug, 2008 - 12:14 AM
Post #3

New D.I.C Head
*

Joined: 17 Aug, 2008
Posts: 5

QUOTE(modi123_1 @ 18 Aug, 2008 - 09:06 AM) *

Not to be a dick or anything, but you shouldn't put your company's database log in out to the world to see... that's pretty dumb.

Second, your problem is you are not not taking into account the multiple values in the text box - only the last one. What you need to do is either call the database for each line in the multi-line textbox and store that row that comes back into a temporary dataset until you are done with all ten, or collect all your rows, format them into a string like "(<value1>, <value2>, ...)" and have your stored procedure take in that string and run your select statement as

CODE

SELECT Count(*) FROM firstflight.TRANSHIP
WHERE (CNNO IN '<that string i told you to make>')



oh.. and never do a select * on production code.. that's just juvenile.


Hai dear,

Thanx for ur kind help. But i am unable to understand. It will be useful for me, if u type the correct program from my program containing errors. sorry for the disturbances.






User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 01:50PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month